home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / objcissu.lha / class-variables < prev    next >
Internet Message Format  |  1993-03-01  |  107KB

  1. Return-Path: <dudney@pencom.com>
  2. Date: Mon, 22 Feb 93 16:28:55 GMT-0600
  3. From: Bill Dudney <dudney@pencom.com>
  4. To: gnu-objc@gnu.ai.mit.edu
  5. Subject: Class Variables
  6.  
  7. Hi All,
  8.  
  9. I have been thinking about class variables and I dont see a reason, in the runtime system,  
  10. why we could not put them into the language. The problem I see is in the syntax of doing  
  11. this. Maybe we could use something like @classVar or @ivars and @cvars (@ivars  
  12. assumed) for differentiating between the two. What do you all think?
  13.  
  14. Thanks,
  15.  
  16.  
  17. Bill Dudney
  18.  
  19. Return-Path: <krab@iesd.auc.dk>
  20. Date: Tue, 23 Feb 1993 00:16:40 +0100
  21. From: Kresten Krab Thorup <krab@iesd.auc.dk>
  22. To: Bill Dudney <dudney@pencom.com>
  23. Cc: gnu-objc@gnu.ai.mit.edu
  24. In-Reply-To: <9302222228.AA01434@>
  25. Subject: Class Variables
  26.  
  27. Bill Dudney writes:
  28. >I have been thinking about class variables and I dont see a reason,
  29. >in the runtime system, why we could not put them into the language.
  30. >The problem I see is in the syntax of doing this. Maybe we could use
  31. >something like @classVar or @ivars and @cvars (@ivars assumed) for
  32. >differentiating between the two. What do you all think? 
  33.  
  34. You're right, I see no reason for not to have class variables either.
  35. There are several things like this.  For instance, implementing some
  36. kind of blocks as known in Smalltalk (using gcc nested functions)
  37. would be another good idea.  I have plenty of ideas like this... :-)
  38.  
  39. However, we *must* have the runtime finished before we can afford to
  40. use time for exploring such issues.
  41.  
  42. /Kresten
  43.  
  44. Return-Path: <wiltel!bshirley@uunet.UU.NET>
  45. From: Bill Shirley <wiltel!bshirley@uunet.UU.NET>
  46. Date: Mon, 22 Feb 93 16:53:27 -0600
  47. To: Bill Dudney <dudney@pencom.com>
  48. Subject: Re: Class Variables
  49. Cc: gnu-objc@gnu.ai.mit.edu
  50.  
  51. > Hi All,
  52.  
  53. > I have been thinking about class variables and I dont see a reason, in the
  54. > runtime system, why we could not put them into the language. The problem I
  55. > see is in the syntax of doing this. Maybe we could use something like
  56. > @classVar or @ivars and @cvars (@ivars assumed) for differentiating
  57. > between the two. What do you all think? 
  58.  
  59.  
  60. I prefer a simpler (in my mind) syntax like...
  61.  
  62. @interface MyClass : Object
  63. {
  64.   id        instanceVar;
  65.   static int    instanceCount;
  66. }
  67.  
  68. what do you think about overworking the 'static' keyword a little more?
  69.  
  70.  
  71. > Thanks,
  72.  
  73.  
  74. > Bill Dudney
  75.  
  76. >
  77.  
  78. ---
  79. Bill Shirley                NeXTmail accepted
  80. Internet: BShirley%Wiltel@relay1.uu.net    USENET: ? uunet!wiltel!bshirley ?
  81. Voice:    (713) 364-4124  
  82.  
  83. Return-Path: <alta@starr.com>
  84. Date: Mon, 22 Feb 93 18:32:16 GMT-0500
  85. From: alta@starr.com (Rex Riley)
  86. To: gnu-objc@gnu.ai.mit.edu
  87. Subject: Re: Class Variables
  88. Reply-To: rr86@cunixa.cc.columbia.edu
  89.  
  90. Bill Dudney <dudney@pencom.com>
  91. > Maybe we could use something like @classVar or @ivars and @cvars  
  92. >(@ivars assumed) 
  93.  
  94.  
  95. Break ------------------------- < Einstein Reality Check >
  96.  
  97. "Everything should be made as simple as possible, but not simpler."  
  98. --
  99. How much complexity for simplicity's sake?  Will Gnu Obj-C join the  
  100. C++ race for most powerful, expressive, and complex language?
  101. -r
  102.                           ----------------------------- Continue
  103.  
  104. Return-Path: <rms@gnu.ai.mit.edu>
  105. Date: Tue, 23 Feb 93 00:50:59 -0500
  106. From: rms@gnu.ai.mit.edu (Richard Stallman)
  107. To: wiltel!bshirley@uunet.uu.net
  108. Cc: dudney@pencom.com, gnu-objc@gnu.ai.mit.edu
  109. In-Reply-To: <9302222253.AA07241@wtg20.> (message from Bill Shirley on Mon, 22 Feb 93 16:53:27 -0600)
  110. Subject: Class Variables
  111.  
  112. I like `static' for this.  This is a natural extension
  113. of its usual meaning, and is also what C++ uses for the same idea.
  114.  
  115. Return-Path: <murphy@murphy.gun.com>
  116. Date: Tue, 23 Feb 1993 09:09:25 -0500
  117. From: Paul Murphy <murphy@murphy.gun.com>
  118. To: rms@gnu.ai.mit.edu
  119. Cc: wiltel!bshirley@uunet.uu.net, dudney@pencom.com, gnu-objc@gnu.ai.mit.edu
  120. In-Reply-To: Richard Stallman's message of Tue, 23 Feb 93 00:50:59 -0500 <9302230550.AA09085@geech.gnu.ai.mit.edu>
  121. Subject: Class Variables
  122.  
  123. I don't like the idea of keywords having different meanings depending on
  124. their context.  Since C and ObjC are often mixed with great liberty you
  125. really can start to think of this as context and not *only* language.
  126. If I write a C function in a file that implements some ObjC methods I
  127. can end up with the same keyword having two meanings only a few lines
  128. apart.  
  129.  
  130. Besides, I don't think C++ is a very good example for many things,
  131. especially syntax.
  132.  
  133.  
  134.    Date: Tue, 23 Feb 93 00:50:59 -0500
  135.    From: rms@gnu.ai.mit.edu (Richard Stallman)
  136.  
  137.    I like `static' for this.  This is a natural extension
  138.    of its usual meaning, and is also what C++ uses for the same idea.
  139.  
  140. Return-Path: <lupson@geom.umn.edu>
  141. Date: Tue, 23 Feb 93 11:31:07 -0600
  142. From: lupson@geom.umn.edu
  143. To: gnu-objc@gnu.ai.mit.edu
  144. Subject: Re: Class Variables
  145. Cc: lupson@geom.umn.edu
  146. Reply-To: lupson@geom.umn.edu
  147.  
  148. Rex Riley <alta@starr.com> writes:
  149. > How much complexity for simplicity's sake?  Will Gnu Obj-C join the C++
  150. > race for most powerful, expressive, and complex language?
  151.  
  152. Class variables would seem to be a small, simple, and useful extension to  
  153. the language.  Both Paul and I have recently run into the need for the  
  154. kind of functionality that class variables would provide.  Currently this  
  155. functionality is implemented with static variables, but that approach  
  156. unfortunately complicates subclassing.  It would seem to me that using  
  157. static variables for class management makes the language more complex than  
  158. using class variables.
  159.  
  160. An alternate approach within the current language would be to make a  
  161. single instance of a "class manager" object and use it (instead of the  
  162. class object) to do bookkeeping.  However, this is ugly.
  163.  
  164. One issue that has not been brought up yet is what impact class managed  
  165. instances would have on distributed objects (regardless of whether it is  
  166. implemented as class variables, static variables, or class manager  
  167. objects).  If you have proxies flying around and you ask a class something  
  168. like [MyClass numberOfInstances] you would have a problem.  On the other  
  169. hand, things might just work out in the wash if the use of class variables  
  170. is limited to "accepting the responsibility" of creating something.  The  
  171. difference is between every instance of a class having -the same- watchful  
  172. parent, and every instance of a class having -some- watchful parent.  In  
  173. one sense omitting class variables (an making it harder to do class  
  174. management) can be a good thing in that it forces objects to be better  
  175. behaved in a distributed environment.
  176.  
  177. Bill Dudney <uunet!pencom.com!dudney@uunet.UU.NET> writes:
  178. > I prefer a simpler (in my mind) syntax like...
  179. > @interface MyClass : Object
  180. > {
  181. >   id        instanceVar;
  182. >   static int    instanceCount;
  183. > }
  184.  
  185. This looks like it could easily get confusing.  I would prefer a new  
  186. keyword like "class int myClassVar" or something like @classVariables and  
  187. @instanceVariables (with @instanceVariables implied by default).  I would  
  188. also avoid abbreviations...
  189.  
  190. #impt <stdio.h>
  191. @inf myObj:Obj
  192. {
  193.   @cvar
  194.     int i;
  195.   @ivar
  196.     @priv
  197.       char *c;
  198.     @prot
  199.       int j;
  200.     @pub
  201.       void *dat;
  202. }
  203. @end
  204.  
  205. We don't want another creat on our conscience.
  206.  
  207. Linus Upson
  208. The Geometry Center
  209. lupson@geom.umn.edu
  210.  
  211. Return-Path: <Steve_Naroff@NeXT.COM>
  212. From: Steve_Naroff@NeXT.COM (Steve Naroff)
  213. Date: Tue, 23 Feb 93 08:23:23 -0800
  214. To: rms@gnu.ai.mit.edu (Richard Stallman)
  215. Subject: Class Variables
  216. Cc: wiltel!bshirley@uunet.uu.net, dudney@pencom.com, gnu-objc@gnu.ai.mit.edu
  217.  
  218.  
  219. Language implementors may find the use of static natural (for class  
  220. variables), but I am not sure developers will see the beauty. 
  221.  
  222.  
  223. Objective-C currently offers 2 compelling advantages over C++: 
  224.  
  225.  
  226. (1) it has a dynamic runtime.
  227. (2) it is much simpler and easier to learn (than C++).
  228.  
  229. I hope these advantages are considered when extending the language.
  230.  
  231. Nevertheless, your point about C++ using it for the same idea makes  
  232. sense, especially since so many people are learning OOP through C++. 
  233.  
  234.  
  235. Note that C++ is particularly conservative about introducing new  
  236. keywords, which makes it hard to learn. "virtual foo() = 0" is a  
  237. pretty obscure way of introducing (what I think) is a really  
  238. important concept (abstract classes). 
  239.  
  240.  
  241. It seems to me that "static" doesn't describe the feature, it  
  242. describes the implementation. If the keyword described the feature  
  243. (@classVariable, or whatever), we are free to have both static and  
  244. dynamic implementations. When working with an OODB vendor recently,  
  245. the need came up for dynamic class variables that could be added at  
  246. runtime.
  247.  
  248. regards,
  249.  
  250. snaroff.
  251.  
  252. Begin forwarded message:
  253.  
  254. Date: Tue, 23 Feb 93 00:50:59 -0500
  255. From: rms@gnu.ai.mit.edu (Richard Stallman)
  256. To: wiltel!bshirley@uunet.uu.net
  257. Cc: pencom.com!dudney@uunet.uu.net,  
  258. gnu.ai.mit.edu!gnu-objc@uunet.uu.net
  259. In-Reply-To: <9302222253.AA07241@wtg20.> (message from Bill Shirley  
  260. on Mon, 22 Feb 93 16:53:27 -0600)
  261. Subject: Class Variables
  262.  
  263. I like `static' for this.  This is a natural extension
  264. of its usual meaning, and is also what C++ uses for the same idea.
  265.  
  266.  
  267. Return-Path: <Nik_Gervae@NeXT.COM>
  268. From: Nik_Gervae@NeXT.COM (Nik Gervae)
  269. Date: Tue, 23 Feb 93 11:02:13 -0800
  270. To: gnu-objc@gnu.ai.mit.edu
  271. Subject: Re: Class Variables
  272.  
  273. Bill Dudney wrote:
  274.  
  275. > > I have been thinking about class variables and I dont see a reason, in the
  276. > > runtime system, why we could not put them into the language. The problem I
  277. > > see is in the syntax of doing this. Maybe we could use something like
  278. > > @classVar or @ivars and @cvars (@ivars assumed) for differentiating
  279. > > between the two. What do you all think?
  280.  
  281. Bill Shirley replied:
  282.  
  283. > I prefer a simpler (in my mind) syntax like...
  284.  
  285. > @interface MyClass : Object
  286. > {
  287. >   id        instanceVar;
  288. >   static int    instanceCount;
  289. > }
  290.  
  291. > what do you think about overworking the 'static' keyword a little more?
  292.  
  293. Now that seems elegant to me. It does have some semantic problems, though.
  294. My first thought on seeing this, knowing what I do about private ivars,
  295. might be that the overloaded meaning is "@private", not "shared among
  296. instances". It's the idea of scope reduction that occurs in this
  297. scenario.
  298.  
  299. On the other hand, you could regard it as the idea of static in a function
  300. definition being "shared among invocations", parallelling the idea of a
  301. variable "shared among instances." Now *that* ties in very nicely to what
  302. we're trying to do.
  303.  
  304. --
  305. Nik "not an Objective C guru" Gervae
  306. Software Publications    ## S2/8bg+-l+y++-/:!z-n-++o-+/++:x-+:a++:u-+v+:j+-p(eR)
  307. NeXT Computer, Inc.    ## B2(go-t & sburns)f-t+c-!g-(--)k--s---mr-p+
  308. ngervae@next.com    ## [[[[NXDisclaimer alloc] init] disclaim] free];
  309.  
  310.  
  311. Return-Path: <a3bee2!seltd!lerman@mercury.hsi.com>
  312. From: Kenneth Lerman <seltd!lerman@uunet.UU.NET>
  313. X-Mailer: SCO System V Mail (version 3.2)
  314. To: murphy@murphy.gun.com, rms@gnu.ai.mit.edu
  315. Subject: Re: Class Variables
  316. Cc: dudney@pencom.com, gnu-objc@gnu.ai.mit.edu, wiltel!bshirley@murphy.gun.com
  317. Date: Tue, 23 Feb 93 16:32:45 EST
  318.  
  319. Re:
  320.  
  321.    Date: Tue, 23 Feb 93 00:50:59 -0500
  322.    From: rms@gnu.ai.mit.edu (Richard Stallman)
  323.  
  324.    I like `static' for this.  This is a natural extension
  325.    of its usual meaning, and is also what C++ uses for the same idea.
  326.  
  327. The problem I have with this is that I believe that class and instance
  328. variable definitions should be kept separate from each other to avoid
  329. confusion.  Of course, Stallman's suggestion would not preclude
  330. someone with my preference from putting unnecessary (from a language
  331. point of view) divisions in his program.
  332.  
  333. Ken
  334. --
  335. Kenneth Lerman                  ...!uunet!casey!gaboon!seltd!lerman
  336. Systems Essentials Limited                            (203)426-4430
  337. 55 Main Street
  338. Newtown, CT 06470
  339.  
  340.  
  341. Return-Path: <burchard@geom.umn.edu>
  342. Date: Tue, 23 Feb 93 15:56:36 -0600
  343. From: burchard@geom.umn.edu
  344. To: Nik_Gervae@NeXT.COM (Nik Gervae)
  345. Subject: Re: Class Variables
  346. Cc: gnu-objc@gnu.ai.mit.edu
  347.  
  348. Nik_Gervae@NeXT.COM (Nik Gervae) writes:
  349. > Bill Shirley replied:
  350.  
  351. > > I prefer a simpler (in my mind) syntax like...
  352. > >
  353. > > @interface MyClass : Object
  354. > > {
  355. > >   id        instanceVar;
  356. > >   static int    instanceCount;
  357. > > }
  358. > >
  359. > > what do you think about overworking the 'static' keyword a
  360. > > little more?
  361. > [...]
  362.  
  363. > On the other hand, you could regard it as the idea of static
  364. > in a function definition being "shared among
  365. > invocations", parallelling the idea of a variable
  366. > "shared among instances." Now *that* ties in very nicely
  367. > to what we're trying to do. 
  368.  
  369.  
  370. Actually, the "shared instance variable" concept does not really  
  371. fulfill my idea of the purpose of a "class variable".  This concept  
  372. seems to imply that the variable in question is directly accessible  
  373. to instances, but not necessarily accessible to the class object.
  374.  
  375. What I had in mind was more something like a meta-instance-variable:  
  376. something directly accessible to the class object, and perhaps (given  
  377. a sufficiently benevolent class method) available to its instances as  
  378. well.  It is definitely necessary for many applications that the  
  379. class be able to access this variable whether or not any instances  
  380. exist.
  381.  
  382. (The bottom line is that classes need to be as much like objects as  
  383. possible---why deny the benefits of OOP to OOP itself?)
  384.  
  385. --------------------------------------------------------------------
  386. Paul Burchard    <burchard@geom.umn.edu>
  387. ``I'm still learning how to count backwards from infinity...''
  388. --------------------------------------------------------------------
  389.  
  390. Return-Path: <burchard@geom.umn.edu>
  391. Date: Tue, 23 Feb 93 16:58:48 -0600
  392. From: burchard@geom.umn.edu
  393. To: Nik_Gervae@NeXT.COM (Nik Gervae)
  394. Subject: Re: Class Variables
  395. Cc: gnu-objc@gnu.ai.mit.edu
  396.  
  397. How about this...
  398.  
  399. We already define instance and class _methods_ in the same place, but  
  400. use (+) and (-) to distinguish them.  Why not do the same with  
  401. instance and class variables (i.e., variables visible within the  
  402. scope of instance and class methods, respectively)?
  403.  
  404. @interface MyClass
  405. {
  406.   @-
  407.     // variables visible within instance methods
  408.     id anInstanceVariable;
  409.   @+
  410.     // variables visible within class methods
  411.     id aClassVariable;
  412. }
  413.  
  414. + classGetsThisOne;
  415.     // self is the class; aClassVariable is in scope
  416.  
  417. - instanceGetsThisOne;
  418.     // self is an instance; anInstanceVariable is in scope
  419.  
  420. @end
  421.  
  422. Return-Path: <lupson@geom.umn.edu>
  423. Date: Tue, 23 Feb 93 17:32:04 -0600
  424. From: lupson@geom.umn.edu
  425. To: gnu-objc@gnu.ai.mit.edu
  426. Subject: Re: Class Variables
  427. Reply-To: lupson@geom.umn.edu
  428.  
  429. Paul Burchard <burchard@geom.umn.edu> writes:
  430. > How about this...
  431. > @interface MyClass
  432. > {
  433. >   @-
  434. >     // variables visible within instance methods
  435. >     id anInstanceVariable;
  436. >   @+
  437. >     // variables visible within class methods
  438. >     id aClassVariable;
  439. > }
  440.  
  441. I'd take it one step further...
  442.  
  443. @interface MyClass:MySuperClass
  444. {
  445.   + id aClassVariable;
  446.   - id anInstanceVairable;
  447. }
  448. @end
  449.  
  450. ("-" would be implied when no modifier is present.)
  451.  
  452. Linus Upson
  453. The Geometry Center
  454. lupson@geom.umn.edu
  455.  
  456. Return-Path: <dudney@pencom.com>
  457. Date: Tue, 23 Feb 93 17:07:53 GMT-0600
  458. From: Bill Dudney <dudney@pencom.com>
  459. To: Steve_Naroff@next.com (Steve Naroff)
  460. Subject: Re: Class Variables
  461. Cc: gnu-objc@gnu.ai.mit.edu
  462.  
  463.  
  464.  
  465. >Begin forwarded message:
  466. >
  467. >From: Steve_Naroff@next.com (Steve Naroff)
  468. >Date: Tue, 23 Feb 93 08:23:23 -0800
  469. >To: rms@gnu.ai.mit.edu (Richard Stallman)
  470. >Subject: Class Variables
  471. >Cc: @uunet.uu.net:wiltel!bshirley, @uunet.uu.net:pencom.com!dudney,
  472. >        @uunet.uu.net:gnu.ai.mit.edu!gnu-objc
  473. >
  474. >
  475. >Language implementors may find the use of static natural (for class variables), but I am  
  476. >not sure developers will see the beauty.
  477. >
  478. >Objective-C currently offers 2 compelling advantages over C++:
  479. >
  480. >(1) it has a dynamic runtime.
  481. >(2) it is much simpler and easier to learn (than C++).
  482. >
  483. >I hope these advantages are considered when extending the language.
  484. >
  485. >Nevertheless, your point about C++ using it for the same idea makes sense, especially  
  486. >since so many people are learning OOP through C++.
  487.  
  488. As was noted eairler C++ is not a very good model to start from. I would argue that many  
  489. people do not learn OOP/OOA from C++ (dont want a flame). It is just to easy not to do  
  490. OOP with C++ you can get away with murdering the OO paradigm.
  491.  
  492. >
  493. >Note that C++ is particularly conservative about introducing new keywords, which makes  
  494. >it hard to learn. "virtual foo() = 0" is a pretty obscure way of introducing (what I think) is a  
  495. >really important concept (abstract classes).
  496.  
  497. I think instead of conservative you mean liberal if so I would agree. A good argument for  
  498. not adding new keywords or other strangeness (i.e. virtual). But IMHO @classVariables is  
  499. not "to much" and would not be a large addition.
  500.  
  501. >
  502. >It seems to me that "static" doesn't describe the feature, it describes the implementation.  
  503. >If the keyword described the feature (@classVariable, or whatever), we are free to have  
  504. >both static and dynamic implementations. When working with an OODB vendor recently,  
  505. >the need came up for dynamic class variables that could be added at runtime.
  506.  
  507. Indeed! IMHO the feature would be best added and easiest to use through some feature  
  508. as @classVariable or what ever. I can see the point that we dont want to add many new  
  509. key words (no C++) but I think this is a usefull feature.
  510.  
  511. BTW I think you can already add class variables dynamically on a NeXT with some of the  
  512. runtime functions, then change them with other functions i.e. objc_createIvarList(),  
  513. objc_addIvars(), object_getClassVariable()...
  514.  
  515. Again, I think this would be a useful additional and I have enjoyed this thread.
  516.  
  517. Thanks,
  518.  
  519. Bill
  520.  
  521.  
  522. >
  523. >regards,
  524. >
  525. >snaroff.
  526. >
  527. [rms comments deleted]
  528.  
  529. Return-Path: <dudney@pencom.com>
  530. Date: Tue, 23 Feb 93 17:14:20 GMT-0600
  531. From: Bill Dudney <dudney@pencom.com>
  532. To: Nik_Gervae@next.com (Nik Gervae)
  533. Subject: Re: Class Variables
  534. Cc: gnu-objc@gnu.ai.mit.edu
  535.  
  536. [some of the thread deleted]
  537.  
  538. >Now that seems elegant to me. It does have some semantic problems, though.
  539. >My first thought on seeing this, knowing what I do about private ivars,
  540. >might be that the overloaded meaning is "@private", not "shared among
  541. >instances". It's the idea of scope reduction that occurs in this
  542. >scenario.
  543.  
  544. Nik hit on something I had not thought about earlier, if we do use static wouldnt the ivar be  
  545. "in scope" in the instance methods, or was rms saying we would add a bigger definition to  
  546. static (in the scope of ivar declarations) that would limit the scope of the variable to class  
  547. methods?
  548.  
  549. >
  550. >On the other hand, you could regard it as the idea of static in a function
  551. >definition being "shared among invocations", parallelling the idea of a
  552. >variable "shared among instances." Now *that* ties in very nicely to what
  553. >we're trying to do.
  554. >
  555. >--
  556. >Nik "not an Objective C guru" Gervae
  557. >Software Publications    ## S2/8bg+-l+y++-/:!z-n-++o-+/++:x-+:a++:u-+v+:j+-p(eR)
  558. >NeXT Computer, Inc.    ## B2(go-t & sburns)f-t+c-!g-(--)k--s---mr-p+
  559. >ngervae@next.com    ## [[[[NXDisclaimer alloc] init] disclaim] free];
  560.  
  561. What Nik, you work at NeXT and are not an Obj-C guru!!??? I am so disapointed!
  562.  
  563. HaVE fun,
  564.  
  565. Bill
  566.  
  567.  
  568. Return-Path: <rms@gnu.ai.mit.edu>
  569. Date: Tue, 23 Feb 93 20:40:18 -0500
  570. From: rms@gnu.ai.mit.edu (Richard Stallman)
  571. To: dudney@pencom.com
  572. Cc: Steve_Naroff@next.com, gnu-objc@gnu.ai.mit.edu
  573. In-Reply-To: <9302232307.AA01993@> (message from Bill Dudney on Tue, 23 Feb 93 17:07:53 GMT-0600)
  574. Subject: Class Variables
  575.  
  576. It was a mistake to design the syntax of Objective C using the special
  577. keywords that start with @.
  578.  
  579. This made the language incoherent.  It looks like two parts grafted
  580. together--rather than like a natural whole.  It could instead have
  581. been done with C-like syntax, making a unified language.
  582.  
  583. This was a hasty job.  It is not something to take as an inspiration.
  584.  
  585. **NOTE** This is a matter of syntax; it has nothing to do with the
  586. semantic differences between Objective C and C++.
  587.  
  588.  
  589. Return-Path: <wiltel!bshirley@uunet.UU.NET>
  590. From: Bill Shirley <wiltel!bshirley@uunet.UU.NET>
  591. Date: Tue, 23 Feb 93 16:29:49 -0600
  592. To: gnu-objc@gnu.ai.mit.edu, Nik_Gervae@NeXT.com
  593. Subject: Re: Class Variables
  594.  
  595.  
  596. >
  597. > From: <uunet!geom.umn.edu!burchard>
  598. >
  599. > Nik_Gervae@NeXT.COM (Nik Gervae) writes:
  600. > > Bill Shirley replied:
  601. > >
  602. > > > I prefer a simpler (in my mind) syntax like...
  603. > > >
  604. > > > @interface MyClass : Object
  605. > > > {
  606. > > >   id        instanceVar;
  607. > > >   static int    instanceCount;
  608. > > > }
  609. > > >
  610. > > > what do you think about overworking the 'static' keyword a
  611. > > > little more?
  612. > > [...]
  613. > >
  614. > > On the other hand, you could regard it as the idea of static
  615. > > in a function definition being "shared among
  616. > > invocations", parallelling the idea of a variable
  617. > > "shared among instances." Now *that* ties in very nicely
  618. > > to what we're trying to do.
  619. >
  620. > Actually, the "shared instance variable" concept does not really fulfill
  621. > my idea of the purpose of a "class variable".  This concept seems to imply
  622. > that the variable in question is directly accessible to instances, but not
  623. > necessarily accessible to the class object.
  624.  
  625. I definately agree with you that the the class variable 'belongs to the class
  626. object', and I think most people mean this when they say it.  We've basically
  627. (as i see it) only been bickering over syntax.
  628.  
  629. I envisioned (without thinking much about it) the instance methods having access
  630. to the class variables *as well as* the class methods.  If, however, someone wants
  631. to argue that the class variables belong to the class and only class methods can
  632. directly reference them, you'll not get to much argument from me (because that will
  633. force nicer code, and eliminate some posible dangers).
  634.  
  635. [example of what I just said]
  636. I had seen
  637.  
  638. - init
  639. {
  640.  [super init];
  641.  instanceCount++;
  642.  return self;
  643. }
  644.  
  645. but i'll go along with...
  646.  
  647. + incrementInstanceCount
  648. {
  649.  instanceCount++;
  650.  return self;
  651. }
  652.  
  653. - init
  654. {
  655.  [super init];
  656.  [[self class] incrementInstanceCount];
  657.  return self;
  658. }
  659.  
  660. but, *definately* the class methods should be able to access the class variables
  661. reguardless of the existance of instances.
  662.  
  663. >
  664. > What I had in mind was more something like a meta-instance-variable:
  665. > something directly accessible to the class object, and perhaps (given a
  666. > sufficiently benevolent class method) available to its instances as
  667. > well.  It is definitely necessary for many applications that the class be
  668. > able to access this variable whether or not any instances exist.
  669.  
  670. what he -----^ said
  671.  
  672. >
  673. > (The bottom line is that classes need to be as much like objects as
  674. > possible---why deny the benefits of OOP to OOP itself?)
  675.  
  676. exactly, each class is only an instance of Class 
  677.  
  678.  
  679. >
  680. > --------------------------------------------------------------------
  681. > Paul Burchard    <burchard@geom.umn.edu>
  682. > ``I'm still learning how to count backwards from infinity...''
  683. > --------------------------------------------------------------------
  684. >
  685. >
  686.  
  687. Bill Shirley
  688.   'bickering over semantics or being pedantic?'
  689.  
  690. BShirley%Wiltel@relay1.uu.net
  691.  
  692.  
  693. Return-Path: <rs05@gte.com>
  694. To: gnu-objc@gnu.ai.mit.edu
  695. Subject: Re: Class Variables 
  696. Date: Wed, 24 Feb 93 10:10:43 -0500
  697. From: rs05@gte.com
  698. X-Mts: smtp
  699.  
  700.  
  701. regarding Class vars, Linus Upson wrote:
  702.  
  703. > I'd take it one step further...
  704. > @interface MyClass:MySuperClass
  705. > {
  706. >   + id aClassVariable;
  707. >   - id anInstanceVairable;
  708. > }
  709. > @end
  710. > ("-" would be implied when no modifier is present.)
  711.  
  712. this is the best proposal I've seen. makes perfect sense,
  713. given this is the way methods are defined as well. it would 
  714. read nicely in the @interface header files. I also liked the
  715. part about class variable scoping rules following the 
  716. conventions established for instance variables, so that 
  717. 'aClassVariable' would be accessible to class methods.
  718.  
  719. Richard Stallman wrote:
  720.  
  721. > It was a mistake to design the syntax of Objective C using the special
  722. > keywords that start with @.
  723. > This made the language incoherent.  It looks like two parts grafted
  724. > together--rather than like a natural whole.  It could instead have
  725. > been done with C-like syntax, making a unified language.
  726.  
  727. Nobody disputes that the @-stuff and the [obj: msg] stuff 
  728. looks like an alien invasion of our beloved C homeland. 
  729.  
  730. But ... that's what it is SUPPOSED to be. Obj-C does not
  731. hide the fact that it is a layer on top of C. It does not
  732. pretend to be a stand-alone language; it is a simple graft
  733. of Smalltalk messaging syntax plus some class construction
  734. frobbery onto vanilla C structs. Inventing new keywords 
  735. (or reusing old ones) to try and 'integrate' the two more 
  736. closely will only serve to confuse matters. 
  737.  
  738. The 'beauty' (if you can call it that) of ObjC is in its 
  739. simplicity and 'separateness' as a pure extension layer 
  740. on top of C. If you want to add new features, you should
  741. stick with the conventions that have already been established,
  742. even though you may disagree with them. Consistency counts.
  743.  
  744. For implementation stuff, go crazy; use sparse arrays and
  745. whatever else to make this tortoise run like a rabbit. Just 
  746. don't ignore ten-plus years of language evolution by doing 
  747. some hasty gene-splicing to make the tortoise LOOK like a 
  748. rabbit. It is what it is.
  749.  
  750. --Russ
  751. rs05@gte.com
  752.  
  753. Return-Path: <Nik_Gervae@NeXT.COM>
  754. From: Nik_Gervae@NeXT.COM (Nik Gervae)
  755. Date: Wed, 24 Feb 93 10:19:36 -0800
  756. To: gnu-objc@gnu.ai.mit.edu
  757. Subject: Re: Class variables
  758.  
  759. The talk about class variables only being accessible by the class object
  760. indicates the distinction between (strictly) class variables, which only
  761. the class object sees, and class-instance variables, which the class
  762. object and all instances see. I think I heard somewhere that Smalltalk
  763. has both of these...? My personal preference would be to have just class-
  764. instance variables, rather just class-only variables. If we could manage
  765. both flavors, I might like that, too (then again, I might start wondering
  766. if this OOP thing is really worth all the trouble ;-).
  767.  
  768. --
  769. Nik Gervae
  770. Software Publications    ## S2/8bg+-l+y++-/:!z-n-++o-+/++:x-+:a++:u-+v+:j+-p(eR)
  771. NeXT Computer, Inc.    ## B2(go-t & sburns)f-t+c-!g-(--)k--s---mr-p+
  772. ngervae@next.com    ## [[[[NXDisclaimer alloc] init] disclaim] free];
  773.  
  774. Return-Path: <ssircar@canon.com>
  775. From: ssircar@canon.com (Subrata Sircar)
  776. Date: Wed, 24 Feb 93 10:27:35 -0800
  777. To: rms@gnu.ai.mit.edu (Richard Stallman)
  778. Subject: Re: Class Variables
  779. Cc: gnu-objc@gnu.ai.mit.edu
  780. Reply-To: ssircar@canon.com
  781.  
  782.  
  783. rms@gnu.ai.mit.edu (Richard Stallman) writes (about the "@" keywords):
  784. >This made the language incoherent. It looks like two parts 
  785.  
  786. >grafted together--rather than like a natural whole. It 
  787.  
  788. >could instead have been done with C-like syntax, making a 
  789.  
  790. >unified language. 
  791.  
  792.  
  793. I disagree.  As someone who knew C (and CLU) before learning Objective-C, the @  
  794. keywords were actually helpful; they told me what was going on.  The keywords  
  795. are clear and specify exactly what they mean, making reading and learning such  
  796. code simpler and easier.  I'm not sure what C-like syntax would meet this goal.
  797.  
  798. [As an aside, I'm probably not looking at the problem from a language  
  799. designer's point of view, but rather as someone who was learning it for the  
  800. first time.  From that perspective, the keywords are easy to learn, as opposed  
  801. to some tricks of C-syntax.]
  802.  
  803. Mostly, the keywords seemed to avoid clumsy or unclear syntax; but I don't  
  804. think that C-like syntax is an inspiration anyway.  I would rather see  
  805. additional keywords than overloading of C-syntax, especially if the meaning is  
  806. not crystal clear.
  807.  
  808. In this particular case, I don't think "static" captures the idea of class  
  809. variables quite correctly - I'd rather see @classVar and @instanceVar, or some  
  810. variation thereof.
  811.  
  812. ---
  813. Subrata Sircar|ssircar@canon.com (NextMail ok)|Prophet & SPAMIT Charter Member
  814. Canon Information Systems and I do not share the same views on everything.
  815. "I'm just mad that I missed the sexual revolution." - me
  816. "Yes, but you dress much better as a result." - Mike
  817.  
  818. Return-Path: <Steve_Naroff@NeXT.COM>
  819. From: Steve_Naroff@NeXT.COM (Steve Naroff)
  820. Date: Wed, 24 Feb 93 10:33:30 -0800
  821. To: gnu-objc@gnu.ai.mit.edu
  822. Subject: @-madness
  823. Cc: rms@gnu.ai.mit.edu (Richard Stallman), dudney@pencom.com, snaroff@NeXT.COM
  824.  
  825.  
  826. Russ @ gte wrote:
  827.  
  828.     Nobody disputes that the @-stuff and the [obj: msg] stuff 
  829.  
  830.     looks like an alien invasion of our beloved C homeland. 
  831.  
  832.  
  833.     But ... that's what it is SUPPOSED to be.
  834.  
  835. Exactly. The @-keywords were used so that Objective-C would be fully  
  836. upward compatible with existing C source code. It was a goal to "stay  
  837. out of C's way", as opposed to "build a better C" (ala C++). I can't  
  838. say that it is an "inspiration", but it supports the goal. 
  839.  
  840.  
  841. In fact, originally classes were introduced with "=" and ended with  
  842. "=:". Version 4.0 of Objective-C (which I worked on @ Stepstone)  
  843. changed this to @implementation/@end...which are a bit more  
  844. understandable! Nevertheless, +/- were maintained because they were  
  845. easy to type...I can't stay that they are intuitively obvious either!
  846.  
  847. I don't think it is worthwhile to "abolish the @-keywords" and start  
  848. unifying the existing language with C. Given the benefits Objective-C  
  849. already offers, I hope the group decides on improving it (in the  
  850. spirit that it was developed), rather that work towards a new  
  851. "unified language".
  852.  
  853. Its hard to believe a feature as simple as class variables has  
  854. spawned such a flurry of email. 
  855.  
  856.  
  857. Wait till we get to the hard stuff :-)
  858.  
  859. snaroff.
  860.  
  861. Begin forwarded message:
  862.  
  863. Date: Tue, 23 Feb 93 20:40:18 -0500
  864. From: rms@gnu.ai.mit.edu (Richard Stallman)
  865. To: dudney@pencom.com
  866. Cc: Steve_Naroff@NeXT.COM, gnu-objc@gnu.ai.mit.edu
  867. In-Reply-To: <9302232307.AA01993@> (message from Bill Dudney on Tue,  
  868. 23 Feb 93 17:07:53 GMT-0600)
  869. Subject: Class Variables
  870.  
  871. It was a mistake to design the syntax of Objective C using the  
  872. special
  873. keywords that start with @.
  874.  
  875. This made the language incoherent.  It looks like two parts grafted
  876. together--rather than like a natural whole.  It could instead have
  877. been done with C-like syntax, making a unified language.
  878.  
  879. This was a hasty job.  It is not something to take as an inspiration.
  880.  
  881. **NOTE** This is a matter of syntax; it has nothing to do with the
  882. semantic differences between Objective C and C++.
  883.  
  884.  
  885.  
  886.  
  887. Return-Path: <rms@gnu.ai.mit.edu>
  888. Date: Wed, 24 Feb 93 13:54:26 -0500
  889. From: rms@gnu.ai.mit.edu (Richard Stallman)
  890. To: Steve_Naroff@NeXT.COM
  891. Cc: gnu-objc@gnu.ai.mit.edu, dudney@pencom.com, snaroff@NeXT.COM
  892. In-Reply-To: <9302241833.AA04715@oz.NeXT.COM> (Steve_Naroff@NeXT.COM)
  893. Subject: @-madness
  894.  
  895. It makes sense to make message features orthogonal to the features of
  896. C.  This does not imply they need be an "alien invasion" of C.  That
  897. is a fast and easy way of insuring orthogonality, but not the best
  898. way.
  899.  
  900. It's possible to avoid the mistakes of C++, and write features with
  901. the semantics of Objective C, using constructs which are both similar
  902. in spirit to C syntax, and orthogonal to the existing C constructs.
  903.  
  904. I'm not saying we should redesign the syntax of Objective C now.  That
  905. would be a lot of work that isn't strictly necessary, and it's
  906. unlikely Objective C users would switch even if they agreed it were
  907. better.
  908.  
  909. Return-Path: <billb@jupiter.fnbc.com>
  910. From: billb@jupiter.fnbc.com (Bill Burcham)
  911. Date: Wed, 24 Feb 93 14:34:33 -0600
  912. To: Steve_Naroff@next.com (Steve Naroff)
  913. Subject: Re: Class Variables
  914. Cc: GnuObjcProj@fnbc.com
  915.  
  916. <good stuff re: new syntax to specify class variables ommited>
  917.  
  918. I realize we need to get this thing out the door, but while everyone  
  919. is thinking about the class variable issue maybe we could make a stab  
  920. at fixing a problem (instead of arguing about another symptom).
  921.  
  922. I think that the real problem is that instances of class Class are  
  923. not treated the same as instances of instances of class Class.  Now I  
  924. am not saying (yet) that we should go to a prototype/instance  
  925. language (where every object can essentially be a class object).  I  
  926. just think that we could treat "class" objects in a way more akin to  
  927. the way we treat "instance" objects.
  928.  
  929. My suggestion is that we split Class stuff from instance stuff in our  
  930. source code.
  931.  
  932. -------Date.ch-------
  933. #import <objc/Object.ch>
  934. @interface DateClass:Class
  935. {   id listOfAllDates;
  936. }
  937. - alloc;  // Notice we don't need funky + anymore
  938. // A bunch of Date class methods could go here
  939. @end
  940. -------Date.cm-------
  941. #import "Date.ch"
  942. @interface DateClass
  943. {   id listOfAllDates;
  944. }
  945. // A bunch of DateClass methods could go here
  946. @end
  947. -------Date.ih-------
  948. #import <objc/Object.ih>
  949. @interface Date:Object
  950. {   int julianDate;
  951. }
  952. - setStringValue:(const char*)str;
  953. - (const char*)stringValue;
  954. - addBusinessDays:(int)howmany; // etc...
  955. @end
  956. -------Date.im-------
  957. #import "Date.ih"
  958. @implementation Date
  959. // A bunch of instance methods go here
  960. @end
  961.  
  962. Notice:
  963.  
  964. 1) DateClass is a subclass of Class and represents class state and  
  965. functionality for Dates.
  966. 2) We actually remove some syntax as there is no more need for `+'  
  967. methods.
  968. 3) I realize that there are some _big_ _holes_ in this proposal -- it  
  969. is not _fully_ thought out yet, but I wanted to get your ideas on it.
  970.  
  971. PS Since starting this post, I have read lots more stuff from the  
  972. list.  In particular these ideas might meld with those expressed by  
  973. Kresten Krab Thorup <krab@iesd.auc.dk>:
  974. > I am considering the possibility to introduce a class
  975. > Class in objective C -- i.e. the class of class Objects,
  976. > somewhat like it is known in Smalltalk. 
  977.  
  978. ---
  979. +--------------------------------+----------------------------------+
  980. |          Bill Burcham          | "Make no small plans; they have  |
  981. | First National Bank of Chicago | no magic to stir men's souls"    |
  982. |    billb@fnbc.com  (NeXTmail)  |      Daniel J. Burnham           |
  983. +--------------------------------+----------------------------------+
  984.  
  985. Return-Path: <a3bee2!seltd!lerman@mercury.hsi.com>
  986. From: Kenneth Lerman <seltd!lerman@uunet.UU.NET>
  987. X-Mailer: SCO System V Mail (version 3.2)
  988. To: gnu-objc@gnu.ai.mit.edu, lupson@geom.umn.edu
  989. Subject: Re: Class Variables
  990. Date: Wed, 24 Feb 93 15:44:28 EST
  991.  
  992. I've suggested this before, but I'll try again:
  993.  
  994. @interface Foo : Object
  995. {
  996.     // class variables go here
  997. }
  998. :  // a delimeter of some type, could be @, or whatever
  999. {
  1000.     // instance variables go here
  1001. }
  1002.  
  1003. Has some advantages over other suggestions
  1004.  
  1005. 1 -- class and instance variables are appropriately grouped
  1006. 2 -- existing code need not be changed
  1007. 3 -- does not add new MODES to the language (think about it):
  1008.      @-
  1009.      instanceVars
  1010.      @+
  1011.      classVars
  1012.  
  1013.      Adds lexemes which cause the mode to be switched.  IMHO, this
  1014.      is as nasty in a language as it is in an editor.
  1015.  
  1016. The disadvantage of my suggestion is that the order of the two
  1017. sections is arbitrary, without a mnemonic way of knowing which section
  1018. comes first.
  1019.  
  1020. Another advantage (which I'm a little  hesitant to mention) is that
  1021. I've already made this change to a version of Stepstone's Objective-C
  1022. compiler.  But that won't (and shouldn't) sway the decision.
  1023.  
  1024. If it were up to me, I would also change the way @public fits into the
  1025. grammar works.  As I've said, I really don't like modes.
  1026.  
  1027. How about:
  1028.  
  1029. @interface Foo : Object
  1030. @instanceVar { @public { // public iVars } // private iVars } @classVar { ...}
  1031.  
  1032. i.e. @public, @private, @instanceVar, @classVar indicate the beginning
  1033. of scopes delimited by {}.  I don't consider that to be the same as a mode.
  1034.  
  1035. Ken
  1036. --
  1037. Kenneth Lerman                  ...!uunet!casey!gaboon!seltd!lerman
  1038. Systems Essentials Limited                            (203)426-4430
  1039. 55 Main Street
  1040. Newtown, CT 06470
  1041.  
  1042.  
  1043. Return-Path: <herring@pd.dth.dk>
  1044. Date: Wed, 24 Feb 93 22:11:29 +0100
  1045. From: Erick Herring <herring@pd.dth.dk>
  1046. To: rms@gnu.ai.mit.edu (Richard Stallman)
  1047. Subject: Re: @-madness
  1048. Cc: Steve_Naroff@NeXT.COM, gnu-objc@gnu.ai.mit.edu, dudney@pencom.com
  1049. Reply-To: herring@pd.dth.dk
  1050.  
  1051. I think that it is worthwhile to note that, conceptually, the @-keywords are  
  1052. delimiters.  Using some form of an @-construction as a  
  1053. type-modifier/storage-class seems to weaken the (again, conceptual)  
  1054. cohesiveness of the source unit.
  1055.  
  1056. Without to regard to the usefulness of "static" as a class-variable  
  1057. type-modifier/storage-class, I think that it would be useful to find an  
  1058. unambiguous notational convenience for the declaration of class-variables.
  1059.  
  1060. Mr. Stallman is quite correct in pointing out that this is a syntactic issue,  
  1061. and Mr. Naroff is quite correct in his assertion that there is nothing  
  1062. particularly intuitive about the @-notation.  I don't think that anyone will  
  1063. argue that 'i++' is terribly intuitive, though there quite likely exists a  
  1064. large portion of the readers of this list that would assert that it is  
  1065. beautiful.
  1066.  
  1067. I guess that means that I agree with everyone :-)
  1068.  
  1069. As an obligatory statement of opinion, I would like to see something along the  
  1070. lines of 'classvar id' or 'cvar id'.  Even using + and - would be okay, though  
  1071. I am not really very excited about "overloading" the meaning of existing  
  1072. constructs.
  1073.  
  1074. If my 'classvar's end up looking like 'static's to the compiler, then that is  
  1075. just peachy, but I come down on the side of notational convenience and  
  1076. readability -- which includes readability for non-ObjC programmers (who, would,  
  1077. I think, have a rough time with seeing static and having it mean something  
  1078. wildly different than it means in normal C).
  1079.  
  1080. I'm out of breath, now, thanks for your attention.
  1081.  
  1082. Erick
  1083. ---
  1084. -----
  1085. Erick Herring      |  Computation is the art of carefully throwing away
  1086. NeXT Systems Eng.  |  information [while] life is the art of carefully
  1087. Polyteknisk Data   |  throwing away opportunities, an interesting
  1088. (+45) 45 93 37 77  |  coincidental parallel.
  1089. herring@pd.dth.dk  |  1 Guy L. Steele Jr.
  1090.  
  1091. Return-Path: <jr@media.com>
  1092. Date: Wed, 24 Feb 93 15:05:59 -0600
  1093. From: jr@media.com (J.R. Jesson)
  1094. To: gnu-objc@gnu.ai.mit.edu
  1095. Subject: Re: @-madness
  1096.  
  1097. Steve Naroff wrote:
  1098.  
  1099. > Its hard to believe a feature as simple as class variables has spawned 
  1100.  
  1101. > such a flurry of email.
  1102.  
  1103. > Wait till we get to the hard stuff :-)
  1104.  
  1105. > snaroff.
  1106.  
  1107. Actually, I think we shouldn't get to the "hard" stuff until we get the
  1108. "simple" stuff down pat.  I actually find it quite humbling to realize
  1109. that I've been coding around the lack of class variables for about a
  1110. year now, without even realizing it.  Go ahead, make my code obsolete...
  1111.  
  1112. jr
  1113. ---
  1114. -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1115. J.R. Jesson
  1116. Chief Development Dude, All-Around Nice Guy, Wirehead
  1117. Multimedia Learning, Inc. (214)869-8282
  1118. jr@media.com.  - Go Ahead, send NeXTMail!
  1119.  
  1120.  
  1121. Return-Path: <bcox@gmuvax2.gmu.edu>
  1122. Date: Wed, 24 Feb 1993 21:29:36 -0500
  1123. To: gnu-objc@gnu.ai.mit.edu
  1124. From: bcox@gmuvax2.gmu.edu (Brad Cox)
  1125. X-Sender: bcox@gmuvax2 (Unverified)
  1126. Subject: Re: Class Variables
  1127. Cc: rs05@gte.com
  1128.  
  1129. >regarding Class vars, Linus Upson wrote:
  1130. >Nobody disputes that the @-stuff and the [obj: msg] stuff 
  1131. >looks like an alien invasion of our beloved C homeland. 
  1132. >
  1133. >But ... that's what it is SUPPOSED to be. Obj-C does not
  1134. >hide the fact that it is a layer on top of C. It does not
  1135. >pretend to be a stand-alone language; it is a simple graft
  1136. >of Smalltalk messaging syntax plus some class construction
  1137. >frobbery onto vanilla C structs. Inventing new keywords 
  1138. >(or reusing old ones) to try and 'integrate' the two more 
  1139. >closely will only serve to confuse matters. 
  1140.  
  1141. Hear, hear! It was never my intention to design a completely new
  1142. programming language. It was to add the least that was needed to something
  1143. old and trusted to support a new level of software integration (i.e. a
  1144. larger unit of modularity than a subroutine; namely a Software-ICs).
  1145.  
  1146. Now that Objective-C is moving from its C substrate to a C++ substrate, its
  1147. more important than ever to keep the seams straight. Fabricate gate- and
  1148. block-level objects in the C++ level of the language. Assemble chip- and
  1149. higher-level objects in the Objective-C level of the language. Thus both
  1150. fabricate-from-scratch and assemble-from-prefab-components are possible
  1151. *within the same language*, but the two levels are syntactically distinct
  1152. (just as integration levels are distinct in silicon engineering).
  1153. --
  1154.   Brad Cox; bcox@gmuvax2.gmu.edu; 703 993 1142 secy 703 968 8229 evenings 
  1155.  George Mason Program on Social and Organizational Learning; Fairfax VA 22030
  1156. --
  1157.  
  1158.  
  1159. Return-Path: <rms@gnu.ai.mit.edu>
  1160. Date: Thu, 25 Feb 93 00:13:00 -0500
  1161. From: rms@gnu.ai.mit.edu (Richard Stallman)
  1162. To: bcox@gmuvax2.gmu.edu
  1163. Cc: gnu-objc@gnu.ai.mit.edu, rs05@gte.com
  1164. In-Reply-To: <9302250224.AA25272@gmuvax2.gmu.edu> (bcox@gmuvax2.gmu.edu)
  1165. Subject: Class Variables
  1166.  
  1167. I see that you like the idea of having two levels,
  1168. but whether it is really a good idea is another question.
  1169.  
  1170. Return-Path: <corybant!scott@rmnug.org>
  1171. Date: Wed, 24 Feb 93 21:38:51 MST
  1172. From: corybant!scott@rmnug.org (Scott Meyer)
  1173. To: gnu-objc@gnu.ai.mit.edu
  1174. Subject: Re: Class Variables
  1175.  
  1176. > From: lupson@geom.umn.edu
  1177.  
  1178. > Rex Riley <alta@starr.com> writes:
  1179. > > How much complexity for simplicity's sake?  Will Gnu Obj-C join the C++
  1180. > > race for most powerful, expressive, and complex language?
  1181.  
  1182. Right on!  If you want C++, you know where to find it...
  1183.  
  1184. > Class variables would seem to be a small, simple, and useful
  1185. > extension to the language. [...]
  1186.  
  1187. Small, simple, and useful extensions without some sort of plan
  1188. usually cause the system of which they are a part to become
  1189. large, complex and unusable.
  1190.  
  1191. > Currently this functionality is implemented with static
  1192. > variables, but that approach unfortunately complicates
  1193. > subclassing.  It would seem to me that using static variables for
  1194. > class management makes the language more complex than using class
  1195. > variables.
  1196.  
  1197. How does this complicate subclassing?  The difficulty that I assume
  1198. you are referring to is that subclasses cannot get at class variables
  1199. (really static variables) unless the superclass provides methods
  1200. to access the class variables.  This may make you type more, but
  1201. it hardly qualifies as a significant increase in complexity.
  1202.  
  1203. Given that the vast majority of extant Objective C classes seem to
  1204. make do just fine without class variables, why penalize everyone by
  1205. adding a feature that benefits only a few?  Certainly, I can ignore
  1206. features that I don't like, that's what I do when I use C++  :-)
  1207.  
  1208. > An alternate approach within the current language would be to make a
  1209. > single instance of a "class manager" object and use it (instead of the
  1210. > class object) to do bookkeeping.  However, this is ugly.
  1211.  
  1212. Why is this ugly?  Seems like pretty straightforward OO programming.
  1213.  
  1214. The case for class variables hasn't really been made in the discussion
  1215. so far.  Most of the discussion seems to have centered around what sort of  
  1216. syntax should be used to implement them.
  1217.  
  1218. I would much rather see a Smalltalk-style class/metaclass system
  1219. (really just an addition to the runtime) than an isolated "class
  1220. variable" feature (which might hamper later attempts to add
  1221. a class/metaclass system).  Perhaps this is what whoever said "Why
  1222. deny the benefits of OOP to OOP?" was hinting at.  If classes
  1223. were first-class objects, the class variables would just be ordinary
  1224. variables and there would be no need to have any special syntax at all.
  1225.  
  1226. -Scott
  1227.  
  1228. Return-Path: <wiltel!bshirley@uunet.uu.net>
  1229. From: Bill Shirley <wiltel!bshirley@uunet.uu.net>
  1230. Date: Wed, 24 Feb 93 17:37:58 -0600
  1231. To: GNUObjC@uunet.uu.net
  1232. Subject: Class variables
  1233.  
  1234.  
  1235.  
  1236. > The talk about class variables only being accessible by the class object
  1237. > indicates the distinction between (strictly) class variables, which only
  1238. > the class object sees, and class-instance variables, which the class
  1239. > object and all instances see. I think I heard somewhere that Smalltalk
  1240. > has both of these...? My personal preference would be to have just class-
  1241. > instance variables, rather just class-only variables. If we could manage
  1242.  
  1243. My preference would be the opposite, class-only variables.
  1244. If it's instances *need* to access them, it can provide methods to do so.
  1245.  
  1246. And I would prefer NOT to have both.  That would just add some extra unnecesaries.
  1247. Heck, this might start looking like C+-.
  1248.  
  1249. > both flavors, I might like that, too (then again, I might start wondering
  1250. > if this OOP thing is really worth all the trouble ;-).
  1251.  
  1252. You should always doubt yourself, it's healthy. :-)
  1253.  
  1254. > rms@gnu.ai.mit.edu (Richard Stallman) writes (about the "@" keywords):
  1255. > >This made the language incoherent. It looks like two parts
  1256. > >grafted together--rather than like a natural whole. It
  1257. > >could instead have been done with C-like syntax, making a
  1258. > >unified language.
  1259.  
  1260.  
  1261. ssircar@canon.com replies...
  1262.  
  1263. SS > I disagree.  As someone who knew C (and CLU) before learning Objective-C,
  1264. SS > the @ keywords were actually helpful; they told me what was going on.  The
  1265. SS > keywords are clear and specify exactly what they mean, making reading and
  1266. SS > learning such code simpler and easier.  I'm not sure what C-like syntax
  1267. SS > would meet this goal. 
  1268.  
  1269.  
  1270. What I understood the rms quote to be sating is '@' looks grafted, and it probly
  1271. (initialy) was, the @ being a preprocessor flag to catch.  I agree that looks like
  1272. two parts grafted together, but I think that is good.  Subrata mentions that once
  1273. you know C (a natural previous state), the @s denote some of the differences that
  1274. you need to take note of.
  1275.  
  1276. The @keywords and [bracket notate:tions] should affront the C programmer, they 
  1277.  
  1278. are the main step from non-OO to OO.
  1279.  
  1280. SS > In this particular case, I don't think "static" captures the idea of class
  1281. SS > variables quite correctly - I'd rather see @classVar and @instanceVar, or
  1282. SS > some variation thereof. 
  1283.  
  1284.  
  1285. Steve Naroff adds...
  1286. SN > I don't think it is worthwhile to "abolish the @-keywords" and start
  1287. SN > unifying the existing language with C. Given the benefits Objective-C
  1288. SN > already offers, I hope the group decides on improving it (in the spirit that
  1289. SN > it was developed), rather that work towards a new "unified language". 
  1290.  
  1291.  
  1292. agreed 
  1293.  
  1294.  
  1295. Erick Herring adds...
  1296. EH > I think that it is worthwhile to note that, conceptually, the @-keywords
  1297. EH > are delimiters.  Using some form of an @-construction as a
  1298. EH > type-modifier/storage-class seems to weaken the (again, conceptual)
  1299. EH > cohesiveness of the source unit. 
  1300.  
  1301.  
  1302. Definately, this is why I didn't line @classVar, but I don't mind 'class id'.
  1303. I just couldn't figure out why it bothered me.
  1304.  
  1305. Since we're so @happy we could just make it
  1306.  @id classVariable;
  1307.  id  instanceVariable;
  1308.  
  1309.  
  1310.  no I don't like that either.
  1311.  
  1312. Kenneth Lerman says...
  1313. KL > @interface Foo : Object
  1314. KL > @instanceVar { @public { // public iVars } // private iVars } @classVar { ...}
  1315. KL > 
  1316.  
  1317. KL > i.e. @public, @private, @instanceVar, @classVar indicate the beginning
  1318. KL > of scopes delimited by {}.  I don't consider that to be the same as a mode.
  1319.  
  1320. I'd prefer to add as few keywords as possible, but not to skimp where they are needed.
  1321. I think this is a few too many, and a little more structure than needed.
  1322. (Our code might come out looking like X widgets ;-)
  1323.  
  1324.  
  1325. > --
  1326. > Nik Gervae
  1327. > Software Publications    ## S2/8bg+-l+y++-/:!z-n-++o-+/++:x-+:a++:u-+v+:j+-p(eR)
  1328. > NeXT Computer, Inc.    ## B2(go-t & sburns)f-t+c-!g-(--)k--s---mr-p+
  1329. > ngervae@next.com    ## [[[[NXDisclaimer alloc] init] disclaim] free];
  1330.  
  1331.  
  1332.  
  1333. Return-Path: <jsoft!ggf@uu4.psi.com>
  1334. Date: Thu, 25 Feb 93 08:13:15 -0700
  1335. From: Gary Frederick <jsoft!ggf@uu4.psi.com>
  1336. To: bcox@gmuvax2.gmu.edu (Brad Cox)
  1337. Subject: Re: Class Variables
  1338. Cc: gnu-objc@gnu.ai.mit.edu
  1339.  
  1340. >Now that Objective-C is moving from its C substrate to a C++  
  1341. >substrate, its more important than ever to keep the seams straight.
  1342.  
  1343.   I would like to see some dialog on what Objective-C++ should be,  
  1344. and how to get from where we are to where we need to be.  Then  
  1345. specifics can be thrashed out.
  1346.  
  1347. Gary
  1348.  
  1349. Return-Path: <burchard@geom.umn.edu>
  1350. Date: Thu, 25 Feb 93 10:26:50 -0600
  1351. From: burchard@geom.umn.edu
  1352. To: corybant!scott@rmnug.org (Scott Meyer)
  1353. Subject: Re: Class Variables
  1354. Cc: gnu-objc@gnu.ai.mit.edu
  1355.  
  1356. corybant!scott@rmnug.org (Scott Meyer) writes:
  1357. > lupson@geom.umn.edu (Linus Upson) writes:
  1358. > > Currently this functionality is implemented with static
  1359. > > variables, but that approach unfortunately complicates
  1360. > > subclassing.  It would seem to me that using static variables for
  1361. > > class management makes the language more complex than using class
  1362. > > variables.
  1363.  
  1364. > How does this complicate subclassing?  The difficulty
  1365. > that I assume you are referring to is that subclasses
  1366. > cannot get at class variables (really static variables)
  1367. > unless the superclass provides methods to access the
  1368. > class variables.  This may make you type more, but it
  1369. > hardly qualifies as a significant increase in
  1370. > complexity.
  1371.  
  1372. No, the difficulty is that with the use of static variables is that  
  1373. subclasses get exactly the same *identical* variable.  There is no  
  1374. automatic way now for each subclass to transparently get access to a  
  1375. distinct instantiation of the same conceptual variable.
  1376.  
  1377. For example, if a class needs to keep track of its instances, you  
  1378. might try to define
  1379.  
  1380.     @implementation BaseClass
  1381.     static unsigned int instanceCount; // faked class variable
  1382.     + (unsigned int *)counter { return &instanceCount; } 
  1383.  
  1384.  
  1385. But then subclasses will automatically inherit and modify BaseClass's  
  1386. instance counter...ooops!  Currently, in order to subclass this  
  1387. behavior, each subclass would be required to define a new static  
  1388. variable and to override the +counter method.
  1389.  
  1390. --------------------------------------------------------------------
  1391. Paul Burchard    <burchard@geom.umn.edu>
  1392. >>>>>>>>>  Global variables: the "GOTO" of the 90's <<<<<<<<<<<<<<<<
  1393. --------------------------------------------------------------------
  1394.  
  1395.  
  1396.  
  1397.  
  1398. Return-Path: <lupson@geom.umn.edu>
  1399. Date: Thu, 25 Feb 93 11:24:52 -0600
  1400. From: lupson@geom.umn.edu
  1401. To: gnu-objc@gnu.ai.mit.edu
  1402. Subject: Re: Class Variables
  1403. Reply-To: lupson@geom.umn.edu
  1404.  
  1405. Scott Meyer <corybant!scott@rmnug.org> writes:
  1406. > Small, simple, and useful extensions without some sort of plan
  1407. > usually cause the system of which they are a part to become
  1408. > large, complex and unusable.
  1409.  
  1410. The idea behind adding class variables is to allow class objects to be  
  1411. complete functional objects (with state) like all other objects in Obj-C.   
  1412. If done properly (which is what we are working out now) class variables  
  1413. will simplify the language -- we will go from the situation, "All objects  
  1414. can have state except for class objects which do not except when hacked  
  1415. with static variables" to the situation, "All objects can have state."
  1416.  
  1417. > How does this complicate subclassing?  The difficulty that I assume
  1418. > you are referring to is that subclasses cannot get at class variables
  1419. > (really static variables) unless the superclass provides methods
  1420. > to access the class variables.  This may make you type more, but
  1421. > it hardly qualifies as a significant increase in complexity.
  1422.  
  1423. If you were to get a hold of a static variable through a message to a  
  1424. superclass (possibly indirectly) you would be getting the superclass'  
  1425. class variable!  If you wanted to properly subclass you would have to  
  1426. redefine the variable in the subclass and make sure that you don't use any  
  1427. of the inherited class methods that access the variable (which would not  
  1428. know about the copy of the variable in the subclass, and instead would act  
  1429. on the variable in the superclass).  Static variables are bad here because  
  1430. they add state to pieces of code, and not to "objects."
  1431.  
  1432. > > An alternate approach within the current language would be to make a
  1433. > > single instance of a "class manager" object and use it (instead of the
  1434. > > class object) to do bookkeeping.  However, this is ugly.
  1435.  
  1436. > Why is this ugly?  Seems like pretty straightforward OO programming.
  1437.  
  1438. It also has subclassing problems -- If you don't subclass both classes  
  1439. (the actual class and its manager) you run into the same difficulty as  
  1440. with statics.  Also, even if you do subclass both of them, what is to  
  1441. prevent the inherited class methods from using the superclass class  
  1442. manager and not the subclass class manager?  Same problem as before.
  1443.  
  1444. Nik Gervae <Nik_Gervae@NeXT.COM> writes:
  1445. > My personal preference would be to have just class-instance variables,
  1446. > rather just class-only variables. If we could manage both flavors, I
  1447. > might like that, too (then again, I might start wondering
  1448. > if this OOP thing is really worth all the trouble ;-)
  1449.  
  1450. You can always share class variables with all the instances of that class  
  1451. by doing something like something like:
  1452.  
  1453. @interface MyClass:MySuperClass
  1454. {
  1455.   + id myClassId;
  1456.   + int myClassInt;
  1457.   int *myInstanceIntPtr;
  1458.   float myInstanceFloat;
  1459. }
  1460. + (int *)revealClassInt;
  1461. - init;
  1462. @end
  1463.  
  1464. @implementation MyClass
  1465. + (int *)revealClassInt
  1466. {
  1467.   return &myClassInt;
  1468. }
  1469. - init
  1470. {
  1471.   [super init];
  1472.   myInstanceIntPtr = [[self class] revealClassInt];
  1473.   return self;
  1474. }
  1475. @end
  1476.  
  1477. But if you have class-instance variables, you can't "put the genie back in  
  1478. the bottle," and you're stuck with the encapsulation leakage.
  1479.  
  1480. Side note:  Notice the [self class] in init.  If MyClass is subclassed,  
  1481. you want to get a pointer to the subclasses myClassInt, not a pointer  
  1482. MyClass' int (maybe I should have picked different variable names :-).
  1483.  
  1484. Second side note: Notice the plug for the "+/-" class variable declaration  
  1485. syntax.  In declaring methods, a "+" means a method only for the class  
  1486. object, and "-" means a method only for the instances of the class.  Since  
  1487. class variables should only be accessible through the class object, and  
  1488. instance variables only accessible through instances of the class, the  
  1489. "+/-" notation for variables is consistent, clear, concise, and non-modal.
  1490.  
  1491. Linus Upson
  1492. The Geometry Center
  1493. lupson@geom.umn.edu
  1494.  
  1495. P.S. I hope I didn't misquote anyone.  In a previous message I transposed  
  1496. Bill Shirley and Bill Burcham, and I noticed that Brad Cox put my name in  
  1497. front of something I didn't write (although I wish I had).  I can see  
  1498. flipping Bill & Bill, but how can you get confused about a Linus? :-)
  1499.  
  1500. Return-Path: <athan@object.com>
  1501. Date: Thu, 25 Feb 93 04:21:54 -0500
  1502. From: athan@object.com (Andrew Athan)
  1503. To: gnu-objc@gnu.ai.mit.edu
  1504. Subject: Re: Class Variables -- be careful!
  1505.  
  1506. 4 sections:
  1507.  
  1508. (1)----------SOMETHING TO AVOID----------------------------------
  1509. Some notes on existing implementations of ObjC (back compatibility  
  1510. issues):  Ivars are visible in class methods.  This is what allows me  
  1511. to do the following (this implies self in the context of the class  
  1512. object IS a instance struct):
  1513.  
  1514. + new
  1515. {
  1516.   self = [Object getMemory];
  1517.   ivarFoo = 10;
  1518.   ivarBar = 20;
  1519.   return self;
  1520. }
  1521.  
  1522. Whatever syntax & semantics are used to reference cvars must not break  
  1523. this.
  1524.  
  1525. Thus, the class object IS an instance object.  It just has different  
  1526. dispatch tables and points to a different superclass--all class objects  
  1527. have Object as their superclass.  The "isa" ivar jacks you into the  
  1528. meta class structs where all this stuff is stored.
  1529.  
  1530.  
  1531.  
  1532.  
  1533. (2)----------MAYBE, SOMETHING NOT TO AVOID-------------------
  1534. Class variables can be implemented in a variety of ways through the use  
  1535. of the existing meta class structs and even existing language  
  1536. semantics.
  1537.  
  1538. E.g.1, the structs themselves can store the ivars & can be put into a  
  1539. heirarchy exactly like class instances work (this is moving towards  
  1540. implementation of a meta class system).  Your isa when you are a class  
  1541. points to a "fat" struct (i.e., with data possibly appended to it).   
  1542. Your isa when you are an instance can point to either a thin (no cvars)  
  1543. or a fat struct (see THUS:...)
  1544.  
  1545. E.g.2, add one ptr to the Class struct to hold a reference to the class  
  1546. data.  The Class struct stays the same no matter what class you are.   
  1547. The cVarsPtr is nil for the isa of an instance.  It takes one extra  
  1548. memory reference to get to cvar data.
  1549.  
  1550. THUS: Both E.g.1 and E.g.2 both allow the syntax of cvar access to be  
  1551. exactly like ivar access.  The semantic, however, is to stick an  
  1552. "isa->" in front of the variable name before applying the regular ivar  
  1553. semantics (e.g., cvarFoo=10; becomes self->isa->cvarFoo=10; instead of  
  1554. self->cvarFoo=10;).  Ivar and Cvar access is therefore syntactically  
  1555. and, strictly speaking, semantically correct everywhere (thus  
  1556. maintaining the low-level equivalence of + and - methods).  Running the  
  1557. code in an instance method, however, gives undefined results if isa  
  1558. points to a thin struct.  If it points to a fat struct, we have come  
  1559. full circle cvars look to instances like ivars look to classes.
  1560.  
  1561.  
  1562.  
  1563.  
  1564. (3)----------IN ANSWER TO A POST-------------------
  1565. Scott Meyer writes:
  1566. > > Currently this functionality is implemented with static
  1567. > > variables, but that approach unfortunately complicates
  1568. > > subclassing.  It would seem to me that using static variables for
  1569. > > class management makes the language more complex than using class
  1570. > > variables.
  1571.  
  1572. > How does this complicate subclassing?  The difficulty that I assume
  1573. > you are referring to is that subclasses cannot get at class variables
  1574. > (really static variables) unless the superclass provides methods
  1575. > to access the class variables.  This may make you type more, but
  1576. > it hardly qualifies as a significant increase in complexity.
  1577.  
  1578.  
  1579. The one major semantic difference you have forgotten is that, like an  
  1580. instance gets its own copies of ivars, a subclass gets its own copies  
  1581. of class variables.  So, the class variable "initCount" (which,say, is  
  1582. incremented in the designated initializer of a class?) declared in  
  1583. class A and referenced in the context of class A has a value.  That  
  1584. same variable referenced in the context of class B (A's subclass) has a  
  1585. different value.
  1586.  
  1587.  
  1588.  
  1589. (4)----------A REMINDER ABOUT objc-runtime-------------------
  1590. There is a special list, gnu-objc-runtime for the discussion of  
  1591. detailed issues pertaining to the implementation of the runtime support  
  1592. system.  Volume on gnu-objc has been light, so it's probably ok to send  
  1593. everything to everyone.  However, I urge you to keep the 4 special  
  1594. purpose lists in mind and to start taking discussions there as you see  
  1595. fit.  Subscription requests to
  1596.     gnu-objc-runtime-request@prep.ai.mit.edu       
  1597.  
  1598.     gnu-objc-map-request@prep.ai.mit.edu
  1599.     gnu-objc-ibex-request@prep.ai.mit.edu
  1600.     gnu-objc-coop-request@prep.ai.mit.edu
  1601.  
  1602.  
  1603. Date: Thu, 25 Feb 93 12:54:06 -0600
  1604. From: burchard@geom.umn.edu
  1605. To: athan@object.com (Andrew Athan)
  1606. Subject: Re: Class Variables -- be careful!
  1607. Cc: gnu-objc@gnu.ai.mit.edu
  1608.  
  1609. athan@object.com (Andrew Athan) writes:
  1610. > (1)----------SOMETHING TO AVOID----------------------------------
  1611. ...
  1612. > + new
  1613. > {
  1614. >   self = [Object getMemory];
  1615. >   ivarFoo = 10;
  1616. >   ivarBar = 20;
  1617. >   return self;
  1618. > }
  1619.  
  1620. Most definitely...it makes my stomach turn to even look at it...
  1621.  
  1622. > Whatever syntax & semantics are used to reference cvars
  1623. > must not break this.
  1624.  
  1625. ???  I hope that no one has ever written any code that uses this horrible hack/loophole.  And if they have, the sooner such programs are exposed, the better, IMHO.
  1626.  
  1627. Lesson: like the Sunday school teacher said, do not play with your self.
  1628.  
  1629. --------------------------------------------------------------------
  1630. Paul Burchard    <burchard@geom.umn.edu>
  1631.   ********** Global variables: the ``GOTO'' of the 90's **********
  1632. --------------------------------------------------------------------
  1633.  
  1634.  
  1635. From: Steve_Naroff@NeXT.COM (Steve Naroff)
  1636. Date: Thu, 25 Feb 93 11:03:08 -0800
  1637. To: athan@object.com (Andrew Athan)
  1638. Subject: Re: Class Variables -- be careful!
  1639. Cc: gnu-objc@gnu.ai.mit.edu
  1640.  
  1641.  
  1642. Andrew writes:
  1643.  
  1644. (1)----------SOMETHING TO AVOID----------------------------------
  1645. Some notes on existing implementations of ObjC (back compatibility issues):  Ivars are visible in class methods. 
  1646.  
  1647. << example >>
  1648.  
  1649. Whatever syntax & semantics are used to reference cvars must not break this.
  1650.  
  1651. snaroff:
  1652.  
  1653. We would really like to change this. Allowing instance variables to be accessed from class methods is EXTREMELY ERROR PRONE. I have been pulled into many debug situation where someone does:
  1654.  
  1655. + new
  1656. {
  1657.   if (someCondition)
  1658.     self = [Object getMemory];
  1659.  
  1660.   ivarFoo = 10;
  1661.   ivarBar = 20;
  1662.   return self;
  1663. }
  1664.  
  1665. If "someCondition" isn't true, self is not initialized and the class data structures in the Objective-C runtime are overwritten...causing things to break pretty quickly! Ever since allocation and initialization have been separated, this practice is much less common (within NeXT at least). Nevertheless, it should be disallowed by the language.
  1666.  
  1667. snaroff.
  1668.  
  1669. To: lupson@geom.umn.edu
  1670. Cc: gnu-objc@gnu.ai.mit.edu, rs05@gte.com
  1671. Subject: Re: Class Variables 
  1672. In-Reply-To: Your message of "Thu, 25 Feb 93 11:24:52 CST."
  1673.              <9302251724.AA00890@minkowski.geom.umn.edu> 
  1674. Date: Thu, 25 Feb 93 13:57:20 -0500
  1675. From: rs05@gte.com
  1676. X-Mts: smtp
  1677.  
  1678.  
  1679. [Linus Upson (lupson@geom.umn.edu) suggests a way to
  1680.  add class vars to the language, while hiding them
  1681.  from instances except through class methods]
  1682.  
  1683. I think this is a rational approach.
  1684.  
  1685. It would be 'convenient' to have direct access to
  1686. those variables, but I agree with Linus that to do
  1687. so would lead to subclasses that are too dependent
  1688. on the superclass implementation.
  1689.  
  1690. also, I think his suggested syntax (below) reads well,
  1691. is quite succinct, is unambiguous, and is consistent with
  1692. the class/instance method designation scheme already
  1693. in place. beautiful it ain't, but it fits in very well.
  1694.  
  1695. --Russ
  1696. rs05@gte.com
  1697.  
  1698. > You can always share class variables with all the instances of that class  
  1699. > by doing something like something like:
  1700. > @interface MyClass:MySuperClass
  1701. > {
  1702. >   + id myClassId;
  1703. >   + int myClassInt;
  1704. >   int *myInstanceIntPtr;
  1705. >   float myInstanceFloat;
  1706. > }
  1707. > + (int *)revealClassInt;
  1708. > - init;
  1709. > @end
  1710. > @implementation MyClass
  1711. > + (int *)revealClassInt
  1712. > {
  1713. >   return &myClassInt;
  1714. > }
  1715. > - init
  1716. > {
  1717. >   [super init];
  1718. >   myInstanceIntPtr = [[self class] revealClassInt];
  1719. >   return self;
  1720. > }
  1721. > @end
  1722. > But if you have class-instance variables, you can't "put the genie back in  
  1723. > the bottle," and you're stuck with the encapsulation leakage.
  1724.  
  1725.  
  1726. Date: Thu, 25 Feb 93 15:09:06 CST
  1727. From: peter@tahiti.umhc.umn.edu
  1728. To: gnu-objc@gnu.ai.mit.edu
  1729. Subject: Re: Class Variables 
  1730.  
  1731.  
  1732.  
  1733.  
  1734. > [Linus Upson (lupson@geom.umn.edu) suggests a way to
  1735. >  add class vars to the language, while hiding them
  1736. >  from instances except through class methods]
  1737.  
  1738. > I think this is a rational approach.
  1739.  
  1740. ditto.
  1741.  
  1742. > ...
  1743. > also, I think his suggested syntax (below) reads well,
  1744. > is quite succinct, is unambiguous, and is consistent with
  1745. > the class/instance method designation scheme already
  1746. > in place. beautiful it ain't, but it fits in very well.
  1747.  
  1748. I agree, but...  If we agree that cvars shouldn't be directly accessed by anyone besides that class, why should any other classes even know they exist other than the methods provided to read/change them?  Cvars have no place in an interface file.  They should be declared and used in the implementation file(s) for that class.  How are they delimited?  I don't know.  The +/- would make sense if cvars and ivars had to be side by side, but if they will ALWAYS be in separate file(s) or atleast separate sections of code that may be enough.
  1749.  
  1750. ie.
  1751.  
  1752. @interface Foo:Object
  1753. {
  1754.    // ivars
  1755. }
  1756. //cmethods
  1757. //imethods
  1758. @end
  1759.  
  1760. @implementation Foo
  1761. (?)
  1762.    // cvars
  1763. (?)
  1764.  
  1765. //cmethods
  1766. //imethods
  1767. @end
  1768.  
  1769.  
  1770. where some person smarter than I would replace the '(?)' with an appropriate symbol.  I like the '{'s but I know that this confilcts with published documents....  (Maybe I've been breaking rules on a NeXT for too long now...)
  1771.  
  1772. peter
  1773. peter@tahiti.umhc.umn.edu (Peter Eisch)
  1774. dig.
  1775.  
  1776.  
  1777. Date: Thu, 25 Feb 93 20:23:51 +0100
  1778. From: Peter Rasmussen <rasmus@dannug.dk>
  1779. To: gnu-objc@prep.ai.mit.edu
  1780. Subject: Re: Class Variables
  1781. Reply-To: rasmus@dannug.dk
  1782.  
  1783. In article ??? burchard@geom.umn.edu writes:
  1784.  
  1785.  
  1786. Hi ..
  1787.  
  1788. Concerning the desire to separate the definition of class and instance variables.
  1789.  
  1790. >  We already define instance and class _methods_ in the same place, but 
  1791. >  use (+) and (-) to distinguish them.  Why not do the same with 
  1792. >  instance and class variables (i.e., variables visible within the 
  1793. >  scope of instance and class methods, respectively)?
  1794. >  @interface MyClass
  1795. >  {
  1796. >    @-
  1797. >      // variables visible within instance methods
  1798. >      id anInstanceVariable;
  1799. >    @+
  1800. >      // variables visible within class methods
  1801. >      id aClassVariable;
  1802. >  }
  1803.  
  1804.  
  1805. To me this depends upon how the concept of how class variables is defined.
  1806.  
  1807. 1)
  1808. As I understand Objective-C class variables are not REALLY supported in the object system. Rather they are ordinary C-language variables layed out in global scope within the .o module of a class.
  1809.  
  1810.     - To hold them encapsulated I do also define them
  1811.       *static* like Stallman suggested.
  1812.      
  1813.     - Since they as C-variables are outside of the ObjC object
  1814.       system do NOT get inherited - I see no reason to declare
  1815.       them in the class @interface.
  1816.      
  1817.       1) They should not be accessed directly by users of class
  1818.       2) Neither by subclass implementors
  1819.       3) So why put their declaration into the @interface def.
  1820.      
  1821. 2)
  1822. If class variables were to be introduced into the GNU Objective-C system object system, then things would be different. Then they would be inherited by subclasses and th
  1823. eir definition would be relevant to place into the @interface def.
  1824.  
  1825. Regards
  1826. Peter Rasmussen
  1827.  
  1828. PS:    Sorry if this got posted twice ...
  1829.  
  1830. --------------------------------------------------------------------
  1831.   Peter Rasmussen                :  Aalborg University       (AUC).
  1832.                                  :  Department of Computer Science.
  1833.   rasmus@dannug.dk (NeXTmail ok) :  9000 Aalborg,       DK-Denmark.
  1834.   Tel/(Fax):       +45 98 145456 :  Office. (+45) 98 154211 # 5000
  1835. --------------------------------------------------------------------
  1836.  
  1837. Date: Thu, 25 Feb 93 15:41:02 -0600
  1838. From: lupson@geom.umn.edu
  1839. To: gnu-objc@gnu.ai.mit.edu
  1840. Subject: Re: Class Variables 
  1841. Reply-To: lupson@geom.umn.edu
  1842.  
  1843. Peter Eisch <peter@tahiti.umhc.umn.edu> writes:
  1844. > If we agree that cvars shouldn't be directly accessed by anyone besides
  1845. > that class, why should any other classes even know they exist other than
  1846. > the methods provided to read/change them?  Cvars have no place in an
  1847. > interface file.  They should be declared and used in the implementation
  1848. > file(s) for that class.
  1849.  
  1850. Inheritance.  Class variables need to be declared in the interface file for the same reason that instance variables need to be declared there -- subclasses need to know what they inherit from their parents.  That way you can subclass somebody else's object without having the source.
  1851.  
  1852. Linus Upson
  1853. The Geometry Center
  1854. lupson@geom.umn.edu
  1855.  
  1856. From: Kenneth Lerman <seltd!lerman@uunet.UU.NET>
  1857. X-Mailer: SCO System V Mail (version 3.2)
  1858. To: burchard@geom.umn.edu, corybant!scott@rmnug.org
  1859. Subject: Re: Class Variables
  1860. Cc: gnu-objc@gnu.ai.mit.edu
  1861. Date: Thu, 25 Feb 93 15:49:50 EST
  1862.  
  1863. Paul Burchard    <burchard@geom.umn.edu> writes:
  1864.  
  1865. No, the difficulty is that with the use of static variables is that  
  1866. subclasses get exactly the same *identical* variable.  There is no  
  1867. automatic way now for each subclass to transparently get access to a  
  1868. distinct instantiation of the same conceptual variable.
  1869.  
  1870. For example, if a class needs to keep track of its instances, you  
  1871. might try to define
  1872.  
  1873.     @implementation BaseClass
  1874.     static unsigned int instanceCount; // faked class variable
  1875.     + (unsigned int *)counter { return &instanceCount; } 
  1876.  
  1877.  
  1878. But then subclasses will automatically inherit and modify BaseClass's  
  1879. instance counter...ooops!  Currently, in order to subclass this  
  1880. behavior, each subclass would be required to define a new static  
  1881. variable and to override the +counter method.
  1882. ---------end of quote-------
  1883.  
  1884. What I've done to get "class variable" like behavior using statics is
  1885. something like:
  1886.  
  1887. SomeClass.h:
  1888.  
  1889. @interface SomeClass : Object
  1890. {}
  1891.  
  1892. #define CV_SomeClass static int instanceCount; \
  1893. + (int)getInstCnt { return instanceCount; } \
  1894. + putInstCnt:(int)cnt { instanceCount = cnt; return self; } \
  1895. + bumpInstCnt { instanceCount++; return self; }  \
  1896. - (int)getInstCnt { return instanceCount; } \
  1897. - putInstCnt:(int)cnt { instanceCount = cnt; return self; } \
  1898. - bumpInstCnt { instanceCount++; return self; }  \
  1899. ...
  1900. // assorted other stuff
  1901. @end
  1902.  
  1903. Then in any class which I want to have these "class variables":
  1904.  
  1905. aClass.m:
  1906.  
  1907. #import "SomeClass.h"
  1908.  
  1909. CV_SomeClass
  1910.  
  1911. ...
  1912. //Whatever else you need
  1913.  
  1914. Note that I've chosen to make "class variables" accessible from both
  1915. classes and instances.
  1916.  
  1917. Ken
  1918. --
  1919. Kenneth Lerman                  ...!uunet!casey!gaboon!seltd!lerman
  1920. Systems Essentials Limited                            (203)426-4430
  1921. 55 Main Street
  1922. Newtown, CT 06470
  1923.  
  1924. Date: Thu, 25 Feb 1993 17:18:54 -0500
  1925. To: gnu-objc@gnu.ai.mit.edu
  1926. From: bcox@gmuvax2.gmu.edu (Brad Cox)
  1927. Subject: Re: Class Variables
  1928. Cc: lupson@geom.umn.edu
  1929.  
  1930. lupson@geom.umn.edu wrote
  1931. >P.S. I hope I didn't misquote anyone.  In a previous message I transposed  
  1932. >Bill Shirley and Bill Burcham, and I noticed that Brad Cox put my name in  
  1933. >front of something I didn't write (although I wish I had).  I can see  
  1934. >flipping Bill & Bill, but how can you get confused about a Linus? :-)
  1935.  
  1936. Whups! Sorry about that. Am using Eudora which makes quoting the
  1937. responsibility of the human, not the machine. In other words, I blew it.
  1938. Sorry about that.
  1939. --
  1940.   Brad Cox; bcox@gmuvax2.gmu.edu; 703 993 1142 secy 703 968 8229 evenings 
  1941.  George Mason Program on Social and Organizational Learning; Fairfax VA 22030
  1942. --
  1943.  
  1944.  
  1945. From: Steve_Naroff@NeXT.COM (Steve Naroff)
  1946. Date: Thu, 25 Feb 93 12:53:58 -0800
  1947. To: Kresten Krab Thorup <krab@iesd.auc.dk>
  1948. Subject: Re: Optimizing the GNU objc runtime [long]
  1949. Cc: gnu-objc@gnu.ai.mit.edu
  1950.  
  1951.  
  1952. Here is some data for a "typical" application on a NeXT (linked with the standard shared library of objects that we supply):
  1953.  
  1954. 200-300 classes
  1955. 6000-7000 method implementations
  1956. 2000-3000 selectors (unique method names)
  1957.  
  1958. Many of these are classes are "private"...nevertheless, it is important that the runtime scale to support a system of this magnitude. It seems like you have already abandoned the idea of a per-class vector that has room for all possible selectors. This is good, since my "back of the envelope" calculation comes out to 3.2 megabytes to store all the caches (using 200 classes, 2000 selectors in the computation)! Let me know if I misinterpreted your proposal.
  1959.  
  1960. It sounds like the sparse array idea might reclaim much of this overhead. I would be interested in how much space that works out to be. The NeXT runtime typically consumes between 20-40 kilobytes for the per-class caches. The space occupied is proportional to the classes/methods used by the application. The simple rule is "pay if you play". In fact, even though there are 200-300 classes linked into an application, only 30-50% are typically used. I think any scalable system must incur mininal overhead (on a per-class basis) until the class is actually used.
  1961.  
  1962. Another method for doing dynamic dispatch (that is similar in spirit to your scheme) is to have a vector that is maintained on a per-app basis (not per-class) that has an entry for each selector. Each entry would contain a chain of classes that implement the selector...in practice, this chain is very short. A simple way to view this is go from the selector->class, rather than class->selector. I'm not convinced it statisfies your performance goals, but it is another way to look at the problem.
  1963.  
  1964. I think it is worthwhile goal to improve the performance of dispatching messages in Objective-C. Just be aware that it is a classic "time vs. space" problem...and saving time without carefully considering space doesn't work. Most computers are getting a lot faster without adding significantly more memory...this should influence the tradeoffs we make when designing the new runtime (my perspective, of course).
  1965.  
  1966. In the past, we have spent time optimizing memory utilization and improving locality of reference. This includes the data generated by the compiler as well as caches that are dynamically allocated (which are often "hot" for commonly used classes). We also developed a program called "objcopt" that improves launch time by building the selector hash table and "freeze drying" it in the executable for each shared library that we ship.
  1967.  
  1968. Given the portability goals of the project, I can't say that many of these apply to the GNU runtime...I just wanted to let you know what problems we work on wrt optimizing the NeXT Objective-C runtime.
  1969.  
  1970. btw...the NeXT runtime sends the "+initialize" lazily, was the change to execute before main() made intentionally?
  1971.  
  1972. regards,
  1973.  
  1974. snaroff.
  1975.  
  1976. Date: Thu, 25 Feb 93 18:04:54 -0500
  1977. From: rms@gnu.ai.mit.edu (Richard Stallman)
  1978. To: Steve_Naroff@NeXT.COM
  1979. Cc: krab@iesd.auc.dk, gnu-objc@gnu.ai.mit.edu
  1980. In-Reply-To: <9302252054.AA20409@oz.NeXT.COM> (Steve_Naroff@NeXT.COM)
  1981. Subject: Optimizing the GNU objc runtime [long]
  1982.  
  1983.     In fact, even though there are 200-300 classes linked into  
  1984.     an application, only 30-50% are typically used. I think any scalable  
  1985.     system must incur mininal overhead (on a per-class basis) until the  
  1986.     class is actually used. 
  1987.  
  1988. It ought to be possible to delay setting up a class's method dispatch
  1989. table until the first time it is instantiated.  Until then you need
  1990. only the dispatch mechanism for the methods that act on the class
  1991. rather than on an instance.  I expect there will be much fewer
  1992. operations of that sort.
  1993.  
  1994.  
  1995. Date: Fri, 26 Feb 1993 00:53:14 +0100
  1996. From: Kresten Krab Thorup <krab@iesd.auc.dk>
  1997. To: Steve_Naroff@NeXT.COM (Steve Naroff)
  1998. Cc: Kresten Krab Thorup <krab@iesd.auc.dk>, gnu-objc@gnu.ai.mit.edu
  1999. In-Reply-To: <9302252054.AA20409@oz.NeXT.COM>
  2000. Subject: Re: Optimizing the GNU objc runtime [long]
  2001.  
  2002. Steve Naroff writes:
  2003. > It seems like you have already abandoned the idea of a  
  2004. >per-class vector that has room for all possible selectors. This is  
  2005. >good, since my "back of the envelope" calculation comes out to 3.2  
  2006. >megabytes to store all the caches (using 200 classes, 2000 selectors  
  2007. >in the computation)! Let me know if I misinterpreted your proposal.
  2008.  
  2009. You're right.  Obviously we cannot have an array with domaine of all
  2010. selectors for each class.   I have been in this belief for some time
  2011. now.  The comments in the `Optimizing ...' article were to make it
  2012. clear that this was not the subject of the paper.
  2013.  
  2014. >It sounds like the sparse array idea might reclaim much of this  
  2015. >overhead. I would be interested in how much space that works out to  
  2016. >be.
  2017.  
  2018. I have a prototype of the runtime up running using sparse arrays for
  2019. dispatch.  Ok, I compiled the first program successfull 10 minutes
  2020. ago, so I'll have to test it a bit more before it's worth distributing!
  2021.  
  2022. >The NeXT runtime typically consumes between 20-40 kilobytes for  
  2023. >the per-class caches. The space occupied is proportional to the  
  2024. >classes/methods used by the application. The simple rule is "pay if  
  2025. >you play". In fact, even though there are 200-300 classes linked into  
  2026. >an application, only 30-50% are typically used. I think any scalable  
  2027. >system must incur mininal overhead (on a per-class basis) until the  
  2028. >class is actually used. 
  2029.  
  2030. This mechanism could be adopted to install the tables incrementally,
  2031. if only we had objc_msgSendv!!!  Please, if someone is into assember
  2032. and gcc internals do it!  I dont know far enough about assember to do
  2033. it, who could we possibly ask?
  2034.  
  2035. I am very excited to see some performace result from my new runtime.
  2036. Sadly enough I will be gone for the weekend :-)  
  2037.  
  2038. I myself is actually very fond of using caches and ordinary dynamic
  2039. lookup.  This has one big advantage which my scheme will have to pay
  2040. for: It is simple to add methods to excisting classes at runtime.  On
  2041. the other hand, by installing magic handlers in the dispatch table, my
  2042. scheme allows the programmer to install his own messenger on class
  2043. basis. I guess to think of a nice API for this ..
  2044.  
  2045. >Given the portability goals of the project, I can't say that many of  
  2046. >these apply to the GNU runtime...I just wanted to let you know what  
  2047. >problems we work on wrt optimizing the NeXT Objective-C runtime.
  2048.  
  2049. I dont know for sure.  I guess most things written in GNU objc will
  2050. probably NOT be large applications with zillions of classes and using
  2051. dynamic loading.  At least it will take some time before this will be
  2052. the case, since class libraries and loading stuff is not easily
  2053. accessible... Several operating systems provide facilities -- I know,
  2054. but far from all.
  2055.  
  2056. >btw...the NeXT runtime sends the "+initialize" lazily, was the change  
  2057. >to execute before main() made intentionally?
  2058.  
  2059. Initially, yes.  The problem is that if you access variables
  2060. initialized in "+initialize" directly (without a message call) you are
  2061. not sure about the state of these.  After having talked to some fellow
  2062. students, I may have changed my mind, but one must enforce the
  2063. constraint that such variables may only be accessed through method
  2064. invocations.  It may be a problem, if class variables are introduced,
  2065. that you can say MyClass->aVariable, but aVariable is assigned its
  2066. default value in "+initialize" !
  2067.  
  2068. I hope to be able to release a beta version of my new runtime within a
  2069. week or so.  It may be that someone are interested in studying it? :-)
  2070.  
  2071. /Kresten
  2072.  
  2073. Date: Fri, 26 Feb 1993 01:21:01 +0100
  2074. From: Kresten Krab Thorup <krab@iesd.auc.dk>
  2075. To: rms@gnu.ai.mit.edu (Richard Stallman)
  2076. Cc: Steve_Naroff@NeXT.COM, krab@iesd.auc.dk, gnu-objc@gnu.ai.mit.edu
  2077. In-Reply-To: <9302252304.AA06929@mole.gnu.ai.mit.edu>
  2078. Subject: Optimizing the GNU objc runtime [long]
  2079.  
  2080. Richard Stallman writes:
  2081. >It ought to be possible to delay setting up a class's method dispatch
  2082. >table until the first time it is instantiated.  Until then you need
  2083. >only the dispatch mechanism for the methods that act on the class
  2084. >rather than on an instance.  I expect there will be much fewer
  2085. >operations of that sort.
  2086.  
  2087. This is easily done using the sparse array scheme.  To do it, we would
  2088. initially install a dispatch table where the empty bucket is filled
  2089. with some function which installs the right dispatch table and forwards
  2090. the message.  We will however need the ability to do forwarding.  
  2091.  
  2092. Do you think we can find someone who'd like to implement a forwarding
  2093. primitive?  At least the primitive one (__builtin_forward) we've been
  2094. talking about which does not allow one to do anything after the
  2095. forward.  Using this we could implement the lazy dispatch table setup,
  2096. as well as lazy initialization.
  2097.  
  2098. /Kresten
  2099.  
  2100.  
  2101. Date: Thu, 25 Feb 93 23:37:06 -0800
  2102. From: John Jay Feiler <relief!jjfeiler@uu2.psi.com>
  2103. To: gnu-objc@gnu.ai.mit.edu
  2104. Subject: Re: Class Variables
  2105. Reply-To: relief!jjfeiler@uu2.psi.com
  2106.  
  2107. I think that the introduction of class variables into Obj-C is something that should definitely, be done, and I personally favor the @classVariable idea.  However, there are ways to get around the lack of class variables in Obj-C.  Here's what I do:
  2108.  
  2109. Say I want to have an object of type Foo associated with each class that inherits from class A
  2110.  
  2111. @interface A:Object
  2112. + initialize;
  2113. + (Foo *)foo;
  2114. + setFoo:(Foo *)aFoo;
  2115. @end
  2116.  
  2117. @implementation A
  2118.  
  2119. static HashTable *fooHT;
  2120.  
  2121. + initialize
  2122. {
  2123.     fooHT = [[HashTable alloc] initKeyDesc:"@" valueDesc:"@"];
  2124.     return self;
  2125. }
  2126.  
  2127. + (Foo *)foo
  2128. {
  2129.     Foo *aFoo;
  2130.     if([fooHT isKey:self])
  2131.     {
  2132.         aFoo = [fooHT valueForKey:self];
  2133.     }
  2134.     else
  2135.     {
  2136.         aFoo = [[Foo alloc] init];
  2137.         [self setFoo:aFoo];
  2138.     }
  2139.     return aFoo;
  2140. }
  2141.  
  2142. + setFoo:(Foo *)aFoo
  2143. {
  2144.     [[fooHT insertValue:aFoo key:self] free];
  2145.     return self;
  2146. }
  2147.  
  2148.  
  2149. The HashTable fooHT is static, and only within the scope of the original Class A factory object, but since class methods are inherited, any subclass of A will call the +setFoo: and +getFoo methods above, and each factory object will have its own foo object associated with it.
  2150.  
  2151. Is it pretty?  No.  Does it work?  Yes.  At least until we get class variables implemented, anybody who really needs them can "fake" them.
  2152.  
  2153. Just my $0.02
  2154.  
  2155.     John
  2156.  
  2157. Date: Thu, 25 Feb 93 23:52:34 -0800
  2158. From: John Jay Feiler <relief!jjfeiler@uu2.psi.com>
  2159. To: Steve_Naroff@NeXT.COM (Steve Naroff)
  2160. Subject: Class Variables -- be careful!
  2161. Cc: gnu-objc@gnu.ai.mit.edu
  2162. Reply-To: relief!jjfeiler@uu2.psi.com
  2163.  
  2164. If we don't allow a class method to access instance vars (or reassign self) how should we design objects which only have one instance, such as OpenPanel?  I usually do the following:
  2165.  
  2166. @implementation Foo
  2167.  
  2168. static Foo    *theFoo;
  2169.  
  2170. + new
  2171. {
  2172.     if(theFoo == nil)
  2173.     {
  2174.         self = theFoo = [super new];
  2175.         /* initialize the Foo instance vars */
  2176.     }
  2177.     return self;
  2178. }
  2179. @end
  2180.  
  2181. This allows me to access the single object of class Foo with a simple message:  [Foo new]
  2182.  
  2183. Faking this stuff with an alloc/init pair isn't very clean, and there is certainly use for Classes which only have one instance.
  2184.  
  2185.     John
  2186.  
  2187. >  Andrew writes:
  2188. >  (1)----------SOMETHING TO
  2189. >  AVOID---------------------------------- Some notes on
  2190. >  existing implementations of ObjC (back compatibility
  2191. >  issues):  Ivars are visible in class methods.
  2192. >  << example >>
  2193. >  Whatever syntax & semantics are used to reference cvars
  2194. >  must not break this.
  2195. >  snaroff:
  2196. >  We would really like to change this. Allowing instance
  2197. >  variables to be accessed from class methods is EXTREMELY
  2198. >  ERROR PRONE. I have been pulled into many debug situation
  2199. >  where someone does:
  2200. >  + new {
  2201. >    if (someCondition)
  2202. >      self = [Object getMemory];
  2203. >    ivarFoo = 10; ivarBar = 20; return self; }
  2204. >  If "someCondition" isn't true, self is not initialized
  2205. >  and the class data structures in the Objective-C runtime
  2206. >  are overwritten...causing things to break pretty quickly!
  2207. >  Ever since allocation and initialization have been
  2208. >  separated, this practice is much less common (within NeXT
  2209. >  at least). Nevertheless, it should be disallowed by the
  2210. >  language.
  2211. >  snaroff.
  2212.  
  2213. From: billb@jupiter.fnbc.com (Bill Burcham)
  2214. Date: Fri, 26 Feb 93 09:40:44 -0600
  2215. To: lupson@geom.umn.edu
  2216. Subject: Re: Class Variables 
  2217. Cc: gnu-objc@gnu.ai.mit.edu
  2218.  
  2219. Linus Upson <lupson@geom.umn.edu> writes:
  2220. > Peter Eisch <peter@tahiti.umhc.umn.edu> writes:
  2221. > > If we agree that cvars shouldn't be directly accessed by anyone besides
  2222. > > that class, why should any other classes even know they exist other than
  2223. > > the methods provided to read/change them?  Cvars have no place in an
  2224. > > interface file.  They should be declared and used in the implementation
  2225. > > file(s) for that class.
  2226. >
  2227. > Inheritance.  Class variables need to be declared in the
  2228. > interface file for the same reason that instance
  2229. > variables need to be declared there -- subclasses need to
  2230. > know what they inherit from their parents.  That way you
  2231. > can subclass somebody else's object without having the
  2232. > source.
  2233. >
  2234. > Linus Upson
  2235. > The Geometry Center
  2236. > lupson@geom.umn.edu
  2237.  
  2238. Please feel free to FLAME ME WITH IMPUNITY, but this illustrates the fact that it is _wrong_ to have only one interface file per class.  There is _no_ reason to have _any_ instance variable definitions in an interface file -- other than for subclassing purposes.  The language would be better if we had seperate files for the subclassing interface vs. "use" interface.  To avoid duplication, we could #import the "use" interface into the subclassing interface.  NeXT made the situation a _little_ better by providing the @class stuff so I don't have to #import irrelevant class interface files, but think about it:  there is no such mechanism for forward declaration of protocols!  So, if I want to associate a protocol with one of my ivars (o.k. GNU doesn't have protocols _yet_, but bear with me) then I have to #import that protocol definition -- even though the user of this class DOESN'T HAVE ANY NEED TO HAVE THAT PROTOCOL IN ITS SCOPE.
  2239.  
  2240. If we did this then a "use" interface would start to look suspiciously like (simply) a protocol.  The only thing we would have to add to a protocol would be some way to get the compiler to see the external declaration of the Class.  All of the stuff that we are currently putting in our interface would go into the subclassing interface.
  2241. ---
  2242. +--------------------------------+----------------------------------+
  2243. |          Bill Burcham          | "Make no small plans; they have  |
  2244. | First National Bank of Chicago | no magic to stir men's souls"    |
  2245. |    billb@fnbc.com  (NeXTmail)  |      Daniel J. Burnham           |
  2246. +--------------------------------+----------------------------------+
  2247.  
  2248. Date: Fri, 26 Feb 93 10:25:35 -0600
  2249. From: burchard@geom.umn.edu
  2250. To: relief!jjfeiler@uu2.psi.com
  2251. Subject: Re: Class Variables -- be careful!
  2252. Cc: Steve_Naroff@NeXT.COM (Steve Naroff), gnu-objc@gnu.ai.mit.edu
  2253.  
  2254. > If we don't allow a class method to access instance vars
  2255. > (or reassign self) how should we design objects which
  2256. > only have one instance, such as OpenPanel?  I usually do
  2257. > the following:
  2258.  
  2259. If you *must* do it this way, you can always say what you really mean, and display how you are directly accessing another object's ivars:
  2260.  
  2261. static Foo *theFoo;
  2262. + new
  2263. {
  2264.     if(theFoo == nil)
  2265.     {
  2266.     theFoo = [super new]; //!! relying on super to really alloc
  2267.     theFoo->glub = 10;    //!! directly accessing object's ivars
  2268.     }
  2269.     return theFoo;
  2270. }
  2271.  
  2272. Preferably, though, you would use the protocol that already exists.  This will also subclass nicely:
  2273.  
  2274. static Foo *theFoo;
  2275. + new
  2276. {
  2277.     if(!theFoo) theFoo = [[self alloc] init];
  2278.     return theFoo;
  2279. }
  2280. - init
  2281. {
  2282.     if(![super init]) return nil;
  2283.     glub = 10;
  2284.     return self;
  2285. }
  2286.  
  2287. --------------------------------------------------------------------
  2288. Paul Burchard    <burchard@geom.umn.edu>
  2289.   ********** Global variables: the ``GOTO'' of the 90's **********
  2290. --------------------------------------------------------------------
  2291.  
  2292. Date: Fri, 26 Feb 93 16:29:03 +0100
  2293. From: Peter Rasmussen <rasmus@dannug.dk>
  2294. To: gnu-objc@prep.ai.mit.edu
  2295. Subject: Re: Class Variables
  2296. Reply-To: rasmus@dannug.dk
  2297.  
  2298. Hi,     (sorry If you get this twice - I had a Mail reject)
  2299.  
  2300. I'm not convinsed that class variables must be supported by the ObjC runtime system.
  2301.  
  2302. You seem to seek ENCAPSULATION and INNHERITANCE of class variables by adding language concepts for class variables.
  2303.  
  2304. In fact we have both already:     by the static solution.
  2305.  
  2306.  
  2307. 1) Encapsulation.
  2308.  
  2309. As static C-variables they are only visible within the class .o module. This protects class variables from other classes giving encapsulation between metaclass/metaclass and between class/metaclass. But with one convenient exception.
  2310.  
  2311. ObjC runs an IMPLICIT parallel metahierarchy of "Metaclasses" which enables the lower encapsulation shelters between class/metaclass PAIRS. The implicit metaclasses are only supposed to a have a single instance anyway (the class object) so why bother wrapping them into real objects and pay by raising real shelters between class/metaclass PAIRS.
  2312.  
  2313. >From the class side: The benefit of static vars for class variables is that you also can access them directly from instance methods (of the same class only)  - not just class methods. If there were real class variables then instance methods would have to message to class objects to get the class variables.
  2314.  
  2315. >From the metaclass side: Not that much to gain from lower class/metaclass pair barriers.
  2316.  
  2317.  
  2318. 2) Inheritance.
  2319.  
  2320. Here is my main point. Inheritance of class variables does infact already exist with the static solution.
  2321.  
  2322. >  Currently, in order to subclass this behavior, each
  2323. >  subclass would be required to define a new static
  2324. >  variable and to override the +counter method.
  2325. >  #define CV_SomeClass static int instanceCount; \ +
  2326. >  (int)getInstCnt { return instanceCount; } \ +
  2327. >  putInstCnt:(int)cnt { instanceCount = cnt; return
  2328. >  self; } \ + bumpInstCnt { instanceCount++; return
  2329. >  self; }  \
  2330.  
  2331. No - it is not necesseary to put NEW static class variables into each subclass. (I saw Kenneth use macro'es to make this easier). With this usage static becomes a bad and redundant solution - I agree.
  2332.  
  2333. Instead setup a subclass implementors interface for the static class variables. This means giving class methods to make them accessible. These class methods automatically gets inherited by your new IMPLICIT metaclass. And it is the subclass implementors responsibility to respect your subclass interface !!!
  2334.  
  2335. Let me give a simple example:
  2336.  
  2337. ------------------------ BaseClass --------------
  2338.  
  2339. static int count;    // the class variable
  2340.  
  2341. @implementation BaseClass:Object
  2342. {
  2343. }
  2344. + initialize        { count = 5; return self; }
  2345. + (int)getCount        { return count; }
  2346. + setCount:(int)i    { count = i; return self; }
  2347. @end
  2348.  
  2349. ------------------------ ClassA --------------
  2350.  
  2351. @implementation ClassA:BaseClass
  2352. {
  2353. }
  2354. + hereAmI        { return self; }
  2355. @end
  2356.  
  2357. ------------------------ Usage --------------
  2358.  
  2359. printf("Initialized %d\n, [BaseClass getCount]);
  2360.  
  2361. [ClassA setCount:10];        
  2362. printf("New count %d\n", [ClassA getCount]);
  2363.  
  2364. ------------------------ Execution --------------
  2365.  
  2366. Initialized 5
  2367. New count 10
  2368.  
  2369.  
  2370. So what is it that you seek by introducing class variables besides what can be achieved by static.  OK - I need to set up class methods to access the STATIC class variables. But you would have to do that any way when wrapping the class variables into class-objects (from which there only exist a single anyway)
  2371.  
  2372. Regards
  2373.  
  2374. Peter Rasmussen
  2375.  
  2376. --------------------------------------------------------------------
  2377.   Peter Rasmussen                :  Aalborg University       (AUC).
  2378.                                  :  Department of Computer Science.
  2379.   rasmus@dannug.dk (NeXTmail ok) :  9000 Aalborg,       DK-Denmark.
  2380.   Tel/(Fax):       +45 98 145456 :  Office. (+45) 98 154211 # 5000
  2381. --------------------------------------------------------------------
  2382.  
  2383. Date: Fri, 26 Feb 93 11:32:17 -0600
  2384. From: burchard@geom.umn.edu
  2385. To: gnu-objc@gnu.ai.mit.edu
  2386. Subject: Re: Class Variables -- be careful!
  2387. Cc: relief!jjfeiler@uu2.psi.com, Steve_Naroff@NeXT.COM (Steve Naroff),
  2388.         gnu-objc@gnu.ai.mit.edu
  2389.  
  2390. I wrote:
  2391. > Preferably, though, you would use the protocol that
  2392. > already exists.  This will also subclass nicely:
  2393. >
  2394. > static Foo *theFoo;
  2395. > + new
  2396. > {
  2397. >     if(!theFoo) theFoo = [[self alloc] init];
  2398. >     return theFoo;
  2399. > }
  2400. > - init
  2401. > {
  2402. >     if(![super init]) return nil;
  2403. >     glub = 10;
  2404. >     return self;
  2405. > }
  2406. >
  2407.  
  2408. (I should have said, this will subclass nicely modulo the ever-present class variable problem.  To really subclass this without class variables, we must in addition use John's trick and replace references to theFoo with class methods which retrieve the correct "class var" from a static HashTable that maps classes -> "class var" pointers.  Sorry for any confusion.)
  2409.  
  2410. --------------------------------------------------------------------
  2411. Paul Burchard    <burchard@geom.umn.edu>
  2412.   ********** Global variables: the ``GOTO'' of the 90's **********
  2413. --------------------------------------------------------------------
  2414.  
  2415.  
  2416.  
  2417. Date: Fri, 26 Feb 93 20:12:14 +0100
  2418. From: Peter Rasmussen <rasmus@dannug.dk>
  2419. To: gnu-objc@prep.ai.mit.edu
  2420. Subject: Re: Class Variables
  2421. Reply-To: rasmus@dannug.dk
  2422.  
  2423.  
  2424. Paul Burchard wrote:
  2425.  
  2426. >  > printf("Initialized %d\n, [BaseClass getCount]);
  2427. >  > > [ClassA setCount:10]; > printf("New count %d\n",
  2428. >  [ClassA getCount]);
  2429. >  Your code does NOT implement "class variables"....it
  2430. >  will give an incorrect answer for the next call to
  2431. >  [BaseClass getCount].  The call to [ClassA setCount:10]
  2432. >  has the "side effect" of also changing [BaseClass
  2433. >  getCount].
  2434.  
  2435. Sure it does. This "side effect" was the whole intension. That ALL objects being kindOf BaseClass are able to share some non-redundant state.
  2436.  
  2437. This is "class variables" seen from the User Objects point of view
  2438. Holding User domain information.
  2439.  
  2440.  
  2441. >  This is because there is no class variable inheritance
  2442. >  here (inheritance of class *methods*, yes, of class
  2443. >  *variables*, no).  If "count" is a class variable
  2444. >  that means I want to count each class separately.
  2445.  
  2446. I get your point. Yes - There is also the other point of view of "Class variables". Where they hold information of their own - only relevant within the Class objects domain.
  2447.  
  2448. Lets take Kenneths example classes housekeeping how many instances they have. Sure this task would take a counting variable for each class. Separated yes - but why isolated ? Update of these "class variables" for counting ought to propagate within class methods.
  2449.  
  2450. If I instantiate eg. a View, I have also put one more object of all of its superclasses into play. So their instance counts should be updated also ...
  2451.  
  2452.  
  2453. static int count;
  2454. @implementation BaseClass:Object
  2455. {
  2456. }
  2457.  
  2458. + initialize
  2459. { count = 0; return self; }
  2460.  
  2461. + (int)getCount
  2462. { return count; }
  2463.  
  2464. + bumpInstCnt
  2465.   { count++; return self; }
  2466. @end
  2467.  
  2468. ------------------------------
  2469.  
  2470. static int count;
  2471. @implementation ClassA:BaseClass
  2472. {
  2473. }
  2474.  
  2475. + bumpInstCnt
  2476. { count++; return [super bumpInstCnt]; }
  2477. @end
  2478.  
  2479.  
  2480. And yes in this class object domain pt. of view it should be remembered to replicate class variables.
  2481.  
  2482. /Peter
  2483.  
  2484.  
  2485. From: Peter Eisch <peter@tahiti.umhc.umn.edu>
  2486. Date: Fri, 26 Feb 93 15:13:55 -0600
  2487. To: rasmus@dannug.dk
  2488. Subject: Re: Class Variables
  2489. Cc: gnu-objc@prep.ai.mit.edu
  2490.  
  2491.  
  2492.  
  2493. Peter Rasmussen <rasmus@dannug.dk> wrote:
  2494. >
  2495. > Paul Burchard wrote:
  2496. > >  This is because there is no class variable inheritance
  2497. > >  here (inheritance of class *methods*, yes, of class
  2498. > >  *variables*, no).  If "count" is a class variable
  2499. > >  that means I want to count each class separately.
  2500. >
  2501. > I get your point. Yes - There is also the other point of view of "Class variables". Where they hold information of their own - only relevant within the Class objects domain.
  2502. >
  2503.  
  2504. Put simply, the SCOPE of "Class Variables" should only be the class in which they are declared.  They should not be visible to subclasses though the methods that manipulate them (if necessary) would be provided.
  2505.  
  2506. peter
  2507. peter@tahiti.umhc.umn.edu (Peter Eisch)
  2508. dig.
  2509.  
  2510. Date: Fri, 26 Feb 93 19:28:50 -0500
  2511. From: athan@object.com (Andrew Athan)
  2512. To: gnu-objc@prep.ai.mit.edu
  2513. Subject: Another interesting point (static)
  2514.  
  2515.  
  2516. A new user of Obj-C once was surprised by the following:
  2517.  
  2518. @implementation Foobar
  2519.  
  2520. - aMethod
  2521. {
  2522.   static int x=10;
  2523.   x=20;
  2524. }
  2525.  
  2526. @end
  2527.  
  2528. The guy had two instances of Foobar, and called aMethod on each.  He was surprised to find that x==20 on entry into the second instance's call.
  2529.  
  2530. "Oh!" he said.  "x is static in the same sense as in a static var in a function.  I was expecting each instance to have a local static copy."
  2531.  
  2532. "... like an ivar, you mean?" someone replied.
  2533.  
  2534. Andrew Athan
  2535. Objective Technologies, Inc.
  2536.  
  2537. Date: Fri, 26 Feb 93 14:33:12 -0500
  2538. From: athan@object.com (Andrew Athan)
  2539. To: billb@jupiter.fnbc.com (Bill Burcham)
  2540. Subject: Re: Class Variables 
  2541. Cc: lupson@geom.umn.edu, gnu-objc@gnu.ai.mit.edu
  2542.  
  2543.  
  2544. > Please feel free to FLAME ME WITH IMPUNITY, but this illustrates the fact that it is _wrong_ to have only one interface file per class
  2545.  
  2546. In general I vote down on any feature of a language which -requires- that I have multiple files.  What are we trying to do, recreate Modula-2?!
  2547.  
  2548. >...
  2549. >If we did this then a "use" interface would start to look suspiciously like (simply) a protocol.
  2550.  
  2551. What you state can already be done with NeXT's objc.  Just do this:
  2552.  
  2553. //this is my "Usage interface file"
  2554. @class ClassA
  2555. @protocol ClassAUsage
  2556. + foobar;
  2557. - foobar;
  2558. @end
  2559.  
  2560. // this is my "Subclassing interface file"
  2561. @interface ClassA:Object < ClassAUsage >
  2562. {
  2563.   ...;
  2564. }
  2565. @end
  2566.  
  2567. // this is my "implementation file"
  2568. @implementation ClassA
  2569. + foobar {}
  2570. - foobar {}
  2571. @end
  2572.  
  2573.  
  2574. > So, if I want to associate a protocol with one of my ivars (o.k. GNU doesn't have protocols _yet_, but bear with me) then I have to #import that protocol definition -- even though the user of this class DOESN'T HAVE ANY NEED TO HAVE THAT PROTOCOL IN ITS SCOPE.
  2575.  
  2576. This question is just one of "how many are too many" features?  As a language definer, I can give you completely normalized declaration/implementation/specification features (normalized = no data repeated, no requirement to have data where you don't need it).  As a language implementor (gcc) I can give you fully defered error management.  Both are at a cost to complexity, which in the first case impacts at least readability (just from the simple standpoint of # of keywords, concepts to learn, etc.) and in the second at least compile time.
  2577.  
  2578. I don't dislike the way things are now in NeXT Obj-C.  I do feel the protocol language extension needs work (there are problems stemming from the actual equivalience of + & - methods in obj-c, and from the -implementation- of the compile time "conformsTo:" checks being too restrictive.  I feel that it's generally ok to have to include most of the .h's for the AppKit just to use even a simple class.  Why?  Because probably, in a large system, you'd find yourself having to spend a LOT of time making your .h's orthogonal anyway.  Why bother?  Just provide things like precomp headers, etc. to make the whole process faster.  This way, you make the problems/errors/bugs less likely.  Don't worry!  Be Happy!
  2579.  
  2580. Andrew Athan
  2581. Objective Technologies, Inc.
  2582.  
  2583. Date: Fri, 26 Feb 93 13:50:51 -0500
  2584. From: athan@object.com (Andrew Athan)
  2585. To: rasmus@dannug.dk
  2586. Subject: Re: Class Variables
  2587. Cc: gnu-objc@prep.ai.mit.edu
  2588.  
  2589. See Peter's message following my sig.  Unless I missunderstand him:
  2590.  
  2591. People keep missing the point!  Let me make it clear: [This is in pseudo objc to keep things short.  I think you understand]
  2592.  
  2593. static statCvar;
  2594. @implementation SuperClass:Object
  2595. {
  2596.     + int realCvar;
  2597. }
  2598.  
  2599. + initialize { realCvar=statCvar=0; }
  2600. + printRealCvar { printf("%s real: %d",[self name],realCvar); }
  2601. + printStatCvar { printf("%s stat: %d",[self name],statCvar); }
  2602. + inc { realCvar++;statCvar++; }
  2603. @end
  2604.  
  2605. @implementation SubClass:SuperClass
  2606. @end
  2607.  
  2608. main()
  2609. {
  2610.     [[SuperClass class] printRealCvar];
  2611.     [[SuperClass class] printStatCvar];
  2612.     [[SubClass class] printRealCvar];
  2613.     [[SubClass class] printStatCvar];
  2614.  
  2615.     [[SubClass class] inc];
  2616.     [[SubClass class] inc];
  2617.     [[SuperClass class] inc];
  2618.  
  2619.     [[SuperClass class] printRealCvar];
  2620.     [[SuperClass class] printStatCvar];
  2621.     [[SubClass class] printRealCvar];
  2622.     [[SubClass class] printStatCvar];
  2623. }
  2624.  
  2625. Result:
  2626.     SuperClass real: 0
  2627.     SuperClass stat: 0
  2628.     SubClass real: 0
  2629.     SubClass stat: 0
  2630.     SuperClass real: 1
  2631.     SuperClass stat: 3
  2632.     SubClass real: 2
  2633.     SubClass stat: 3
  2634.  
  2635. Thus, you see that in a "real" cvar, **each class has its own copy automatically**.  With a static variable **all subclasses share the same memory**.  Just to prove that it can be implemented: one way is by having the ->isa metaclass struct for a class and its subclasses contain any declared realCvar's appended to the normal isa information.  The code realCvar=10; really reads self->isa->realVar=10;.
  2636.  
  2637. Andrew Athan
  2638. Objective Technologies, Inc.
  2639.  
  2640. ============================================
  2641.  
  2642. Peter Rasmussen writes:
  2643. > ...
  2644. > Here is my main point. Inheritance of class variables does infact already exist with the static solution.
  2645. > ...
  2646. > >  Currently, in order to subclass this behavior, each
  2647. > >  subclass would be required to define a new static
  2648. > >  variable and to override the +counter method.
  2649. > >
  2650. > >  #define CV_SomeClass static int instanceCount; \ +
  2651. > >  (int)getInstCnt { return instanceCount; } \ +
  2652. > >  putInstCnt:(int)cnt { instanceCount = cnt; return
  2653. > >  self; } \ + bumpInstCnt { instanceCount++; return
  2654. > >  self; }  \
  2655. >
  2656. > No - it is not necesseary to put NEW static class variables into each subclass. (I saw Kenneth use macro'es to make this easier). With this usage static becomes a bad and redundant solution - I agree.
  2657. >
  2658. > Instead setup a subclass implementors interface for the static class variables. This means giving class methods to make them accessible. These class methods automatically gets inherited by your new IMPLICIT metaclass. And it is the subclass implementors responsibility to respect your subclass interface !!!
  2659. >
  2660. > Let me give a simple example:
  2661. >
  2662. > ------------------------ BaseClass --------------
  2663. >
  2664. > static int count;    // the class variable
  2665. >
  2666. > @implementation BaseClass:Object
  2667. > {
  2668. > }
  2669. > + initialize        { count = 5; return self; }
  2670. > + (int)getCount        { return count; }
  2671. > + setCount:(int)i    { count = i; return self; }
  2672. > @end
  2673. >
  2674. > ------------------------ ClassA --------------
  2675. >
  2676. > @implementation ClassA:BaseClass
  2677. > {
  2678. > }
  2679. > + hereAmI        { return self; }
  2680. > @end
  2681. >
  2682. > ------------------------ Usage --------------
  2683. >
  2684. > printf("Initialized %d\n, [BaseClass getCount]);
  2685. >
  2686. > [ClassA setCount:10];        
  2687. > printf("New count %d\n", [ClassA getCount]);
  2688. >
  2689. > ------------------------ Execution --------------
  2690. >
  2691. > Initialized 5
  2692. > New count 10
  2693. >
  2694. >
  2695. > So what is it that you seek by introducing class variables besides what can be achieved by static.  OK - I need to set up class methods to access the STATIC class variables. But you would have to do that any way when wrapping the class variables into class-objects (from which there only exist a single anyway)
  2696. >
  2697. > Regards
  2698. >
  2699. > Peter Rasmussen
  2700. >
  2701.  
  2702. Date: Fri, 26 Feb 93 19:18:51 -0500
  2703. From: athan@object.com (Andrew Athan)
  2704. To: rasmus@dannug.dk
  2705. Subject: Re: Class Variables
  2706. Cc: gnu-objc@prep.ai.mit.edu
  2707.  
  2708. > I get your point. Yes - There is also the other point of view of "Class variables". Where they hold information of their own - only relevant within the Class objects domain.
  2709. >
  2710. > Lets take Kenneths example classes housekeeping how many instances they have. Sure this task would take a counting variable for each class. Separated yes - but why isolated ? Update of these "class variables" for counting ought to propagate within class methods.
  2711. >
  2712. > If I instantiate eg. a View, I have also put one more object of all of its superclasses into play. So their instance counts should be updated also ...
  2713. >
  2714.  
  2715. The fact that static variables solve your example does not prove anything except that static variables are useful.  The fact that static variables can be used to build class-variable like functionality also does not prove anything.  Neither thing changes the fact that class variables are also useful: In the first case, they solve a different problem.  In the second case, remember: C++ can be mapped onto C, and C onto assembler.
  2716.  
  2717. Andrew Athan
  2718. Objective Technologies, Inc.
  2719.  
  2720.  
  2721. Date: Sat, 27 Feb 93 18:52:42 -0800
  2722. From: John Jay Feiler <relief!jjfeiler@uu2.psi.com>
  2723. To: burchard@geom.umn.edu
  2724. Subject: Class Variables -- be careful!
  2725. Cc: gnu-objc@gnu.ai.mit.edu
  2726. Reply-To: relief!jjfeiler@uu2.psi.com
  2727.  
  2728. The only problem with this is that there isn't anything preventing someone from doing the following:
  2729.  
  2730. - someMethod
  2731. {
  2732.     Foo    *myFoo = [[Foo alloc] init];
  2733.     .....
  2734. }
  2735.  
  2736. and getting a different instance of the Foo class.  I guess if you override the +alloc and +allocFromZone: methods to raise an exception you can avoid this though.
  2737.  
  2738. As far as subclassing goes, using the theFoo = self = [super new] will subclass just as well as the init mechanism.  Of course, if a class has only a single instance, then it's subclasses will likely do the same, and will require their own static variables to point to that instance.
  2739.  
  2740.     John
  2741.  
  2742.  
  2743. Begin forwarded message:
  2744.  
  2745. Date: Fri, 26 Feb 93 10:25:35 -0600
  2746. From: burchard@geom.umn.edu
  2747. To: relief!jjfeiler@uu2.psi.com
  2748. Subject: Re: Class Variables -- be careful!
  2749. Cc: Steve_Naroff@NeXT.COM (Steve Naroff), gnu-objc@gnu.ai.mit.edu
  2750.  
  2751. > If we don't allow a class method to access instance vars
  2752. > (or reassign self) how should we design objects which
  2753. > only have one instance, such as OpenPanel?  I usually do
  2754. > the following:
  2755.  
  2756. If you *must* do it this way, you can always say what you really mean, and display how you are directly accessing another object's ivars:
  2757.  
  2758. static Foo *theFoo;
  2759. + new
  2760. {
  2761.     if(theFoo == nil)
  2762.     {
  2763.     theFoo = [super new]; //!! relying on super to really alloc
  2764.     theFoo->glub = 10;    //!! directly accessing object's ivars
  2765.     }
  2766.     return theFoo;
  2767. }
  2768.  
  2769. Preferably, though, you would use the protocol that already exists.  This will also subclass nicely:
  2770.  
  2771. static Foo *theFoo;
  2772. + new
  2773. {
  2774.     if(!theFoo) theFoo = [[self alloc] init];
  2775.     return theFoo;
  2776. }
  2777. - init
  2778. {
  2779.     if(![super init]) return nil;
  2780.     glub = 10;
  2781.     return self;
  2782. }
  2783.  
  2784. --------------------------------------------------------------------
  2785. Paul Burchard    <burchard@geom.umn.edu>
  2786.   ********** Global variables: the ``GOTO'' of the 90's **********
  2787. --------------------------------------------------------------------
  2788.  
  2789.  
  2790. Date: Sun, 28 Feb 93 10:32:15 EST
  2791. From: jjobe@mrj.com (jason jobe)
  2792. To: peter@tahiti.umhc.umn.edu
  2793. Cc: rasmus@dannug.dk, gnu-objc@prep.ai.mit.edu
  2794. In-Reply-To: Peter Eisch's message of Fri, 26 Feb 93 15:13:55 -0600 <9302262113.AA19988@tahiti.umhc.umn.edu>
  2795. Subject: Class Variables
  2796.  
  2797. > Put simply, the SCOPE of "Class Variables" should only be the class  
  2798. > in which they are declared.  They should not be visible to subclasses  
  2799. > though the methods that manipulate them (if necessary) would be  
  2800. > provided.
  2801.  
  2802. The Dylan spec (availabale from Apple) addresses many of the topics which
  2803. are being discussed here. One might require one to explicitly specifiy if 
  2804. each subclass gets its own copy of the the (class)variable or shares the one
  2805. being declared.
  2806.  
  2807. Jason
  2808.  
  2809. Date: Mon, 1 Mar 93 09:28:53 -0600
  2810. From: jr@media.com (J.R. Jesson)
  2811. To: gnu-objc@gnu.ai.mit.edu
  2812. Subject: Re: Class Variables 
  2813.  
  2814. Bill Burcham <billb@jupiter.fnbc.com> writes:
  2815.  
  2816. [ stuff deleted ]
  2817. > Please feel free to FLAME ME WITH IMPUNITY, but this illustrates the fact
  2818. > that it is _wrong_ to have only one interface file per class.  There is _no_
  2819. > reason to have _any_ instance variable definitions in an interface file --
  2820. > other than for subclassing purposes.  The language would be better if we had
  2821. > seperate files for the subclassing interface vs. "use" interface.  To avoid
  2822. > duplication, we could #import the "use" interface into the subclassing
  2823. > interface.  NeXT made the situation a _little_ better by providing the @class
  2824. > stuff so I don't have to #import irrelevant class interface files, but think
  2825. > about it:  there is no such mechanism for forward declaration of protocols! 
  2826. > So, if I want to associate a protocol with one of my ivars (o.k. GNU doesn't
  2827. > have protocols _yet_, but bear with me) then I have to #import that protocol
  2828. > definition -- even though the user of this class DOESN'T HAVE ANY NEED TO
  2829. > HAVE THAT PROTOCOL IN ITS SCOPE.
  2830. >
  2831. >
  2832. > If we did this then a "use" interface would start to look suspiciously like
  2833. > (simply) a protocol.  The only thing we would have to add to a protocol would
  2834. > be some way to get the compiler to see the external declaration of the Class.
  2835. > All of the stuff that we are currently putting in our interface would go into
  2836. > the subclassing interface.
  2837. >
  2838.  
  2839. No flames here Bill, but I do have a comment ;-).  I think that there is a
  2840. difference between what you propose to do here, and what was previously
  2841. discussed about Class variables.  Class variables give developers a
  2842. more direct way to express important things about the Class.  What you
  2843. propose to do is "protect" the "users" of the compiler from themselves.
  2844. I think its a bad idea to overly protect developers from doing "dumb" things.  This is probably why I like 'C' and dont like Eiffel.  In this case, you
  2845. really propose to add a whole level of constraint and syntax to the language
  2846. ( and the compilers).  At the moment, the compiler doesn't care where
  2847. @interface and @implementation directives are located, so you add a level
  2848. of checking and complexity.  You also run the real risk of having to do
  2849. changes amongst three files, instead of one or two.  Two thumbs down from
  2850. the critic...
  2851.  
  2852. jr
  2853. ---
  2854. -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  2855. J.R. Jesson
  2856. Chief Development Dude, All-Around Nice Guy, Wirehead
  2857. Multimedia Learning, Inc. (214)869-8282
  2858. jr@media.com.  - Go Ahead, send NeXTMail!
  2859.  
  2860.  
  2861.